# to\_json uses single quotes

**URL:** <https://forum.ansible.com/t/to-json-uses-single-quotes/18793>\
**Category:** Ansible Project\
**Created:** [July 17, 2015, 6:08am UTC](https://forum.ansible.com/t/to-json-uses-single-quotes/18793 "2015-07-17T06:08:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [July 17, 2015, 6:08am UTC](https://forum.ansible.com/t/to-json-uses-single-quotes/18793/1 "2015-07-17T06:08:35Z")

</div>

I’ve seen one other post on this from 2014, but it did not really have solution. Whenever I use  
to\_json the resulting json uses single quotes. Then when I later try to use from\_json it does  
not parse.

Is anybody else experiencing this? Any known workarounds?

---

<div class="post-metadata">

**Author:** ![Abhijit\_Menon-Sen1](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@Abhijit\_Menon-Sen1](https://forum.ansible.com/u/Abhijit_Menon-Sen1)\
**Post date:** [July 17, 2015, 1:06pm UTC](https://forum.ansible.com/t/to-json-uses-single-quotes/18793/2 "2015-07-17T13:06:22Z")

</div>

Could you provide more details, please? It worked in the simple case I  
just tried:

&nbsp;&nbsp;&nbsp;&nbsp;$ ansible localhost -m debug -a "msg='{{ p|to\_json }}'" --extra-vars @p.yml  
&nbsp;&nbsp;&nbsp;&nbsp;localhost | success \>\> {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"msg": "[{\"foo\": 1, \"bar\": 2}, {\"buzh\": 42, \"barf\": 2}]"  
&nbsp;&nbsp;&nbsp;&nbsp;}

-- Abhijit

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 17, 2015, 1:18pm UTC](https://forum.ansible.com/t/to-json-uses-single-quotes/18793/3 "2015-07-17T13:18:10Z")

</div>

I normally use from\_yaml as it is much more forgiving than from\_json.

---

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [July 18, 2015, 2:55am UTC](https://forum.ansible.com/t/to-json-uses-single-quotes/18793/4 "2015-07-18T02:55:01Z")

</div>

I’ve been down this path also, and see just what you see. But when I store that value (say  
in consul to be used later) it actually stores the quoted quotes – " – not the parsable json.

I’ll build some simple examples that demonstrate my issues. Hopefully I’m making some silly mistakes.
