# Extract value from json result

**URL:** <https://forum.ansible.com/t/extract-value-from-json-result/27347>\
**Category:** Ansible Project\
**Created:** [April 23, 2018, 9:03am UTC](https://forum.ansible.com/t/extract-value-from-json-result/27347 "2018-04-23T09:03:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antonios\_Dimtsoudis](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Antonios\_Dimtsoudis](https://forum.ansible.com/u/Antonios_Dimtsoudis)\
**Post date:** [April 23, 2018, 9:03am UTC](https://forum.ansible.com/t/extract-value-from-json-result/27347/1 "2018-04-23T09:03:20Z")

</div>

Hi,

i have a problem with using the ansible json-filter.  
 → [http://docs.ansible.com/ansible/latest/user\_guide/playbooks\_filters.html#json-query-filter](http://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#json-query-filter)

from an api-request i get a json response with a token.

‘{{ response[“json”] | to\_json }}’  
results in:  
`  
{“name”: “ltmetric”, “key”: “eyJrIj…”}

`

How can i extract the key-value with the json filter and save it to a file? The solution must be really easy, but i didn’t manage to solve it and tried out several versions of code…

Right now i use echo and jq on shell to get the key, but i think that’s not the best practice 🙂

Thanks,  
Toni.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 23, 2018, 9:16am UTC](https://forum.ansible.com/t/extract-value-from-json-result/27347/2 "2018-04-23T09:16:24Z")

</div>

This might be way off base, but isn’t the key just “{{ response.key }}” ?

Regards, K.

---

<div class="post-metadata">

**Author:** ![Antonios\_Dimtsoudis](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Antonios\_Dimtsoudis](https://forum.ansible.com/u/Antonios_Dimtsoudis)\
**Post date:** [April 23, 2018, 11:10am UTC](https://forum.ansible.com/t/extract-value-from-json-result/27347/3 "2018-04-23T11:10:34Z")

</div>

Not really,  
you get an response object with the key “json”

So something like:  
‘{{ response[“json”] | to\_json }}.key’  
but this doesn’t work…

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 23, 2018, 9:20pm UTC](https://forum.ansible.com/t/extract-value-from-json-result/27347/4 "2018-04-23T21:20:02Z")

</div>

from\_json ... to\_json converts data into a string.
