filter "to_json" and double quotes

1,690 views
Skip to first unread message

Sylvain

unread,
Sep 2, 2016, 4:38:08 PM9/2/16
to Ansible Project
Hi !

I want to export YAML variable to JSON for use with jq tool but the last don't like JSON sent by Ansible.
shell : 'echo {{ var | to_json }} | jq'

For that work, I must quote keys and datas that seems the good way. See here : http://stackoverflow.com/questions/949449/json-spec-does-the-key-have-to-be-surrounded-with-quotes
Is there any possibility to do that with Ansible ?

Thanks,
Sylvain

Matt Martz

unread,
Sep 2, 2016, 4:51:16 PM9/2/16
to ansible...@googlegroups.com
I imagine that the problem is that you need to quote what is being echoed.  Something like:

shell: echo '{{ var | to_json }}' | jq

--
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/26e1240d-d939-4fbe-a373-44d061152922%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Sylvain

unread,
Sep 2, 2016, 4:57:20 PM9/2/16
to ansible...@googlegroups.com
Oh yes, it was that !
I've forgotten that using shell module can eat quoting.
Thanks ! :)

Sylvain

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/E6Shuvt8mX4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.

To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages