title: Why is Ansible unable to read unicode string as JSON?
body: <h2>Summary</h2>
  
  <p>When retrieving data using the uri module in Ansible, I am unable to parse a section of it as JSON to retrieve a nested value.  </p>
  
  <p>The desired value is the <code>ci</code> field inside the <code>content.data</code> or <code>json.data</code> field (see <strong>output</strong> below).  </p>
  
  <h2>Steps to Reproduce</h2>
  
  <p><strong>site.yml</strong>  </p>
  
  <pre><code>--- 
  - hosts: localhost 
    gather_facts: false 
    tasks: 
      - name: Get String 
        uri: 
          url: "http://localhost/get-data" 
          method: POST 
          body_format: json 
          body: "{ \"kong-jid\": \"run-sn-discovery\" }"
          return_content: yes 
        register: output 
  
      - set_fact:
          ci: "{{ output.json.data.ci }}"
  
      - debug:
          msg: "{{ ci }}"
  </code></pre>
  
  <p><strong>The {{ output }} variable</strong></p>
  
  <pre><code>{
    u'status': 200, 
    u'cookies': {}, 
    u'url': u'http://kong-demo:8000/get-data', 
    u'transfer_encoding': u'chunked', 
    u'changed': False, 
    u'connection': u'close', 
    u'server': u'kong/0.34-1-enterprise-edition', 
    u'content': 
    u'{"data":"\\"{u\'ci\': u\'3bb8d625dbac3700e4f07b6e0f96195b\'}\\""}', 
    'failed': False, 
    u'json': {u'data': u'"{u\'ci\': u\'3bb8d625dbac3700e4f07b6e0f96195b\'}"'}, 
    u'content_type': u'application/json', 
    u'date': u'Thu, 18 Apr 2019 15:50:25 GMT', 
    u'redirected': False, 
    u'msg': u'OK (unknown bytes)'
  }
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <pre><code>[user@localhost]$ ansible-playbook site.yml
   [WARNING]: Could not match supplied host pattern, ignoring: all
  
   [WARNING]: provided hosts list is empty, only localhost is available
  
  
  PLAY [localhost] ***************************************************************************************************************
  
  TASK [Pass Redis data to next task as output] **********************************************************************************
  ok: [localhost]
  
  TASK [set_fact] ****************************************************************************************************************
  fatal: [localhost]: FAILED! =&gt; {}
  
  MSG:
  
  The task includes an option with an undefined variable. The error was: 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'ci'
  
  The error appears to have been in 'site.yml': line 19, column 7, but may
  be elsewhere in the file depending on the exact syntax problem.
  
  The offending line appears to be:
  
  
      - set_fact:
        ^ here
  
  exception type: &lt;class 'ansible.errors.AnsibleUndefinedVariable'&gt;
  exception: 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'ci'
  </code></pre>
  
  <h2>Important Troubleshooting Information</h2>
  
  <p>It appears the root issue is related to which Ansible type being interpreted.  I desire to parse <code>ci</code> from the output in one task.  </p>
  
  <p><strong><em>The two-task solution shown below works, but this leads me to believe this should be possible in one line...</em></strong>  </p>
  
  <p><strong>Two-Task Solution</strong>  </p>
  
  <pre><code>- set_fact:
      ci: "{{ output.json.data | from_json }}"
  
  - debug:
      msg: "{{ ci['ci'] }}"
  </code></pre>
  
  <p>But the <code>ci</code> fact set from <code>{{ output.json.data | from_json }}</code> reports a different TYPE than the inline type...  </p>
  
  <p><strong>Unicode or Dict?</strong></p>
  
  <pre><code>- debug:
      msg: "{{ output.json.data | from_json | type_debug }}" # returns unicode
  
  - set_fact:
      ci: "{{ output.json.data | from_json }}"
  
  - debug:
      msg: "{{ ci | type_debug }}" # returns dict
  </code></pre>
  
  <p><strong>Why isn't <code>{{ output.json.data | from_json | type_debug }}</code><br>
  the same as <code>{{ ci | type_debug }}</code>?</strong></p>