# Convert yaml to Json jinja2

**URL:** <https://forum.ansible.com/t/convert-yaml-to-json-jinja2/30024>\
**Category:** Ansible Project\
**Created:** [March 29, 2019, 3:07pm UTC](https://forum.ansible.com/t/convert-yaml-to-json-jinja2/30024 "2019-03-29T15:07:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saranya\_N](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Saranya\_N](https://forum.ansible.com/u/Saranya_N)\
**Post date:** [March 29, 2019, 3:07pm UTC](https://forum.ansible.com/t/convert-yaml-to-json-jinja2/30024/1 "2019-03-29T15:07:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 29, 2019, 4:51pm UTC](https://forum.ansible.com/t/convert-yaml-to-json-jinja2/30024/2 "2019-03-29T16:51:53Z")

</div>

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](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters-for-formatting-data)

Dick
