# Dict to string; using json\_query

**URL:** <https://forum.ansible.com/t/dict-to-string-using-json-query/31478>\
**Category:** Ansible Project\
**Created:** [October 17, 2019, 1:30pm UTC](https://forum.ansible.com/t/dict-to-string-using-json-query/31478 "2019-10-17T13:30:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Green](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@John\_Green](https://forum.ansible.com/u/John_Green)\
**Post date:** [October 17, 2019, 1:30pm UTC](https://forum.ansible.com/t/dict-to-string-using-json-query/31478/1 "2019-10-17T13:30:43Z")

</div>

**In an Ansible playbook, I am using “with\_file” to read a text file off the file system. It returns a dict.**

- name: show cvfr dictionary  
debug:  
msg: “{{item.key}}: {{item.value}}”  
loop: “{{ lookup(‘dict’, cos\_vault\_file) }}”

TASK [show cvfr dictionary] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> (item={‘key’: u’msg’, ‘value’: u’All items completed’}) =\> {  
“msg”: “msg: All items completed”  
}  
ok: [localhost] =\> (item={‘key’: u’changed’, ‘value’: False}) =\> {  
“msg”: “changed: False”  
}  
ok: [localhost] =\> (item={‘key’: u’results’, ‘value’: [{‘failed’: False, ‘ansible\_loop\_var’: u’item’, ‘changed’: False, u’item’: u’{\n “content”: "{\“request\_id\”:\“d5c\"auth\\":null}\\n"\n}', ‘changed’: False}]”  
}

**When I try to use json\_query to get the request\_id, I get a null string.**

set\_fact:  
requestid\_cvfr: “{{cvfr\_file.results | json\_query(‘request\_id’)}}”

After this, requestid\_cvfr is “” where it should be “d5c”.

**But I can print the results key :**

- name: show cvfr results  
debug:  
msg: “Results: {{cvfr\_file.results}}”

TASK [show cvfr results] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“msg”: “Results: [{‘failed’: False, ‘ansible\_loop\_var’: u’item’, ‘changed’: False, u’item’: u’{\n "content”: "{\“request\_id\”:\“d5c\"auth\\":null}\\n"\n}', ‘changed’: False}]”  
}

**Please show me the command needed to retrieve the request\_id from the cvfr\_file.results. If I could use a string, I would get the correct response, but because it is a dict item, json\_query is not able to retrieve the correct value.**

Thanks in advance.
