to_json uses single quotes

82 views
Skip to first unread message

Barry Kaplan

unread,
Jul 17, 2015, 2:08:35 AM7/17/15
to ansible...@googlegroups.com
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?

Brian Coca

unread,
Jul 17, 2015, 9:18:16 AM7/17/15
to ansible...@googlegroups.com
I normally use from_yaml as it is much more forgiving than from_json.

--
Brian Coca

Abhijit Menon-Sen

unread,
Jul 17, 2015, 9:32:51 AM7/17/15
to ansible...@googlegroups.com
At 2015-07-16 23:08:35 -0700, mem...@gmail.com wrote:
>
> Whenever I use to_json the resulting json uses single quotes. Then
> when I later try to use from_json it does not parse.

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

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

-- Abhijit

Barry Kaplan

unread,
Jul 17, 2015, 10:55:02 PM7/17/15
to ansible...@googlegroups.com


On Friday, July 17, 2015 at 7:02:51 PM UTC+5:30, Abhijit Menon-Sen wrote:
Could you provide more details, please? It worked in the simple case I
just tried:

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

-- Abhijit

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. 
Reply all
Reply to author
Forward
0 new messages