Extract value from json result

33 views
Skip to first unread message

Antonios Dimtsoudis

unread,
Apr 23, 2018, 5:03:20 AM4/23/18
to Ansible Project
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

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.

Karl Auer

unread,
Apr 23, 2018, 5:16:38 AM4/23/18
to ansible...@googlegroups.com
This might be way off base, but isn't the key just "{{ response.key }}" ?

Regards, K.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4cf8651b-0bee-4f98-9772-1f394382f0b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Karl Auer

Email  : ka...@2pisoftware.com
Website: 
http://2pisoftware.com

GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA

Antonios Dimtsoudis

unread,
Apr 23, 2018, 7:10:34 AM4/23/18
to Ansible Project
Not really,
you get an response object with the key "json"

So something like:
'{{ response["json"] | to_json }}.key'
but this doesn't work..

Brian Coca

unread,
Apr 23, 2018, 5:20:17 PM4/23/18
to Ansible Project
from_json ... to_json converts data into a string.




--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages