How to convert json to csv

Hi Team,

Anybody knows how to convert json to csv in ansible?

Thanks,
Pushparaj

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
        Racke

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”

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
         Racke

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’