# How to convert json to csv

**URL:** <https://forum.ansible.com/t/how-to-convert-json-to-csv/31688>\
**Category:** Ansible Project\
**Created:** [November 20, 2019, 10:30am UTC](https://forum.ansible.com/t/how-to-convert-json-to-csv/31688 "2019-11-20T10:30:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pushparaj\_Gothandam](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pushparaj_gothandam/32/5538_2.png) [@Pushparaj\_Gothandam](https://forum.ansible.com/u/Pushparaj_Gothandam)\
**Post date:** [November 20, 2019, 10:30am UTC](https://forum.ansible.com/t/how-to-convert-json-to-csv/31688/1 "2019-11-20T10:30:53Z")

</div>

Hi Team,

Anybody knows how to convert json to csv in ansible?

Thanks,  
Pushparaj

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [November 20, 2019, 11:10am UTC](https://forum.ansible.com/t/how-to-convert-json-to-csv/31688/2 "2019-11-20T11:10:23Z")

</div>

> Hi Team,
> 
> Anybody knows how to convert json to csv in ansible?
> 
> Thanks,  
> Pushparaj

What's your use case? I suppose you know you can't convert JSON with a nested structure to CSV?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Pushparaj\_Gothandam](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pushparaj_gothandam/32/5538_2.png) [@Pushparaj\_Gothandam](https://forum.ansible.com/u/Pushparaj_Gothandam)\
**Post date:** [November 20, 2019, 3:43pm UTC](https://forum.ansible.com/t/how-to-convert-json-to-csv/31688/3 "2019-11-20T15:43:12Z")

</div>

Hi Racke,

I parsed the cisco command “show interface status” and converted to json , now I want to convert it to csv.

- name: Write interfaces\_status\_facts to ‘/var/lib/awx/projects/test-sk/show\_interfaces\_status\_facts-[inventory\_hostname].json’  
copy:  
content: “{{ interfaces\_status\_facts | to\_nice\_json }}”  
dest: “/var/lib/awx/projects/test-sk/interfaces\_status\_facts-{{ inventory\_hostname }}.json”

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [November 20, 2019, 4:14pm UTC](https://forum.ansible.com/t/how-to-convert-json-to-csv/31688/4 "2019-11-20T16:14:29Z")

</div>

> Hi Racke,
> 
> I parsed the cisco command "show interface status" and converted to json , now I want to convert it to csv.
> 
> ```
> \- name: Write interfaces\_status\_facts to
> 
> ```
> 
> '/var/lib/awx/projects/test-sk/show\_interfaces\_status\_facts-[inventory\_hostname].json'  
> copy:  
> content: "{{ interfaces\_status\_facts | to\_nice\_json }}"  
> dest: "/var/lib/awx/projects/test-sk/interfaces\_status\_facts-{{ inventory\_hostname }}.json"

So how does the resulting JSON look like? I think it would be easier to convert the "interfaces\_status\_facts" straight  
away to CSV.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Pushparaj\_Gothandam](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pushparaj_gothandam/32/5538_2.png) [@Pushparaj\_Gothandam](https://forum.ansible.com/u/Pushparaj_Gothandam)\
**Post date:** [November 21, 2019, 5:37am UTC](https://forum.ansible.com/t/how-to-convert-json-to-csv/31688/5 "2019-11-21T05:37:01Z")

</div>

Hi Racke

Below is the json output

interfaces\_status\_facts:  
Te1/0/37:  
data:  
duplex: auto  
interface: Te1/0/37  
name: ’ ’  
speed: auto  
status: notconnect  
type: ’ 100/1000/2.5G/5G/10GBaseTX’  
vlan: ‘1’  
Te1/0/38:  
data:  
duplex: auto  
interface: Te1/0/38  
name: interface configur  
speed: auto  
status: notconnect  
type: ’ 100/1000/2.5G/5G/10GBaseTX’  
vlan: ‘25’
