Skip to main content
edited the answer according to moderation
Source Link

You can use the csvkit package from Pypi to accomplish that. Here's one of the tools from csvkit to convert json to csv in python: https://csvkit.readthedocs.io/en/1.0.2/scripts/in2csv.html

Edit:

So making the answer a bit more discriptive, a messy json like this one:

[
   {
      "a1":"1",
      "a2":"2",
      "aa":[
         "a",
         "a"
      ],
      "bb":[
         {
            "b1":1,
            "b2":2
         },
         {
            "b1":1,
            "b2":2
         }
      ]
   },
   {
      "a1":"1",
      "a2":"2",
      "aa":[
         "a",
         "a"
      ],
      "bb":[
         {
            "b1":1,
            "b2":2
         },
         {
            "b1":1,
            "b2":2
         }
      ]
   }
]

Would become a very simple csv file like this one:

a1,a2,aa/0,aa/1,bb/0/b1,bb/0/b2,bb/1/b1,bb/1/b2
1,2,a,a,1,2,1,2
1,2,a,a,1,2,1,2

by just running this command:

pip install csvkit
in2csv -f json < file.json > file.csv

You can use the csvkit package from Pypi to accomplish that. Here's one of the tools from csvkit to convert json to csv in python: https://csvkit.readthedocs.io/en/1.0.2/scripts/in2csv.html

You can use the csvkit package from Pypi to accomplish that. Here's one of the tools from csvkit to convert json to csv in python: https://csvkit.readthedocs.io/en/1.0.2/scripts/in2csv.html

Edit:

So making the answer a bit more discriptive, a messy json like this one:

[
   {
      "a1":"1",
      "a2":"2",
      "aa":[
         "a",
         "a"
      ],
      "bb":[
         {
            "b1":1,
            "b2":2
         },
         {
            "b1":1,
            "b2":2
         }
      ]
   },
   {
      "a1":"1",
      "a2":"2",
      "aa":[
         "a",
         "a"
      ],
      "bb":[
         {
            "b1":1,
            "b2":2
         },
         {
            "b1":1,
            "b2":2
         }
      ]
   }
]

Would become a very simple csv file like this one:

a1,a2,aa/0,aa/1,bb/0/b1,bb/0/b2,bb/1/b1,bb/1/b2
1,2,a,a,1,2,1,2
1,2,a,a,1,2,1,2

by just running this command:

pip install csvkit
in2csv -f json < file.json > file.csv
Source Link

You can use the csvkit package from Pypi to accomplish that. Here's one of the tools from csvkit to convert json to csv in python: https://csvkit.readthedocs.io/en/1.0.2/scripts/in2csv.html