# filter "to\_json" and double quotes

**URL:** <https://forum.ansible.com/t/filter-to-json-and-double-quotes/22468>\
**Category:** Ansible Project\
**Created:** [September 2, 2016, 8:38pm UTC](https://forum.ansible.com/t/filter-to-json-and-double-quotes/22468 "2016-09-02T20:38:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sylvain1](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@Sylvain1](https://forum.ansible.com/u/Sylvain1)\
**Post date:** [September 2, 2016, 8:38pm UTC](https://forum.ansible.com/t/filter-to-json-and-double-quotes/22468/1 "2016-09-02T20:38:07Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 2, 2016, 8:50pm UTC](https://forum.ansible.com/t/filter-to-json-and-double-quotes/22468/2 "2016-09-02T20:50:30Z")

</div>

I imagine that the problem is that you need to quote what is being echoed. Something like:

shell: echo ‘{{ var | to\_json }}’ | jq

---

<div class="post-metadata">

**Author:** ![Sylvain1](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@Sylvain1](https://forum.ansible.com/u/Sylvain1)\
**Post date:** [September 2, 2016, 8:57pm UTC](https://forum.ansible.com/t/filter-to-json-and-double-quotes/22468/3 "2016-09-02T20:57:15Z")

</div>

Oh yes, it was that !  
I’ve forgotten that using shell module can eat quoting.

Thanks ! 🙂

Sylvain
