Open ravikuc opened 6 years ago
The output CSV should look like:
Hi @ravikuc (or rather anyone looking to make it work for python 3
),
I created a fork for Python 3 and added most of the changes made up until today (2020-06) by other forks. I dropped python 2.
If you want to do it by yourself, just the best thing to do would be to execute the python command utility 2to3
with option -w
to convert the deprecated Python 2
code to Python 3
.
For instance on Unix:
2to3 -w json2csv.py
@ravikuc you can flatten json by from flatten_json import flatten. Then apply json2csv
@ravikuc refer to py3 port of the same, https://github.com/brahma19/json2csvpy3
I have tested this in my local and getting this as output
I am trying to convert JSON data into a CSV in Python3, but it no longer works with this script, giving me different errors. Anyone know how to fix for Python 3? Thanks.
Below is my JSON data:
{ "fruit": [ { "name": "Apple", "binomial name": "Malus domestica", "major_producers": [ "China", "United States", "Turkey" ], "nutrition": { "carbohydrates": "13.81g", "fat": "0.17g", "protein": "0.26g" } }, { "name": "Orange", "binomial name": "Citrus x sinensis", "major_producers": [ "Brazil", "United States", "India" ], "nutrition": { "carbohydrates": "11.75g", "fat": "0.12g", "protein": "0.94g" } }, { "name": "Mango", "binomial name": "Mangifera indica", "major_producers": [ "India", "China", "Thailand" ], "nutrition": { "carbohydrates": "15g", "fat": "0.38g", "protein": "0.82g" } } ] }