How to convert json to csv

672 views
Skip to first unread message

rajthecomputerguy

unread,
Nov 20, 2019, 5:30:53 AM11/20/19
to Ansible Project
Hi Team,

Anybody knows how to convert json to csv in ansible?

Thanks,
Pushparaj

Stefan Hornburg (Racke)

unread,
Nov 20, 2019, 6:10:51 AM11/20/19
to ansible...@googlegroups.com
What's your use case? I suppose you know you can't convert JSON with a nested structure to CSV?

Regards
Racke

> --
> 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 <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/6f4a23c6-12ae-4736-abd3-972df733ce6e%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/6f4a23c6-12ae-4736-abd3-972df733ce6e%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

rajthecomputerguy

unread,
Nov 20, 2019, 10:43:12 AM11/20/19
to Ansible Project
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"





On Wednesday, November 20, 2019 at 4:40:51 PM UTC+5:30, Stefan Hornburg (Racke) wrote:
On 11/20/19 11:30 AM, rajthecomputerguy wrote:
> 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

> --
> 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

Stefan Hornburg (Racke)

unread,
Nov 20, 2019, 11:15:03 AM11/20/19
to ansible...@googlegroups.com
On 11/20/19 4:43 PM, rajthecomputerguy wrote:
> 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

>
>
>
>
> On Wednesday, November 20, 2019 at 4:40:51 PM UTC+5:30, Stefan Hornburg (Racke) wrote:
>
> On 11/20/19 11:30 AM, rajthecomputerguy wrote:
> > 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
>
> > --
> > 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...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com <javascript:>>.
> <https://groups.google.com/d/msgid/ansible-project/6f4a23c6-12ae-4736-abd3-972df733ce6e%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/6f4a23c6-12ae-4736-abd3-972df733ce6e%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> 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 <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/aee026d0-a792-464b-be95-c46426c81d88%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/aee026d0-a792-464b-be95-c46426c81d88%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

rajthecomputerguy

unread,
Nov 21, 2019, 12:37:02 AM11/21/19
to Ansible Project
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'
>     > ansible...@googlegroups.com <javascript:> <mailto:ansible-project+unsub...@googlegroups.com <javascript:>>.
>     > To view this discussion on the web visit
>     > https://groups.google.com/d/msgid/ansible-project/6f4a23c6-12ae-4736-abd3-972df733ce6e%40googlegroups.com
>     <https://groups.google.com/d/msgid/ansible-project/6f4a23c6-12ae-4736-abd3-972df733ce6e%40googlegroups.com>
>     >
>     <https://groups.google.com/d/msgid/ansible-project/6f4a23c6-12ae-4736-abd3-972df733ce6e%40googlegroups.com?utm_medium=email&utm_source=footer
>     <https://groups.google.com/d/msgid/ansible-project/6f4a23c6-12ae-4736-abd3-972df733ce6e%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
>     --
>     Ecommerce and Linux consulting + Perl and web application programming.
>     Debian and Sympa administration. Provisioning with Ansible.
>
> --
> 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
Reply all
Reply to author
Forward
0 new messages