Convert yaml to Json jinja2

768 views
Skip to first unread message

Saranya N

unread,
Mar 29, 2019, 11:07:15 AM3/29/19
to Ansible Project
I was able to convert a list of yaml to Json format.

The below is my yaml.

Listofstrings:
- s1
- S2
Etc


{% for in in listofstrings %}
{ Stringslist : [
{ String : " { i } " },
]
{% end %}

So how do I remove the last comma in my json file to ensure proper Json format.

The Q's may sound naive but any help is greatly appreciated.

Dick Visser

unread,
Mar 29, 2019, 12:52:14 PM3/29/19
to ansible...@googlegroups.com
I wouldn't recommend handcrafting json. Have a look at the to_json and
to_nice_json filters:

https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters-for-formatting-data

Dick
> --
> 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-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c062ba83-6fc4-4e80-8d50-2d7e504c42e3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT
Reply all
Reply to author
Forward
0 new messages