how to convert json to csv in python

后端 未结 4 846
时光取名叫无心
时光取名叫无心 2020-12-19 22:27

Following is my json file input

{\"userID\": \"679d3bad-155e-4b39-9ff7-7d564f408942\", \"Is salary credited before 5th\": \"Yes\", \"Avg Salary of last 3 mon         


        
4条回答
  •  长情又很酷
    2020-12-19 23:14

    GeekSambhu's solution worked for me with a minor modification. I modified it a little because like Vinsent, I saw a KeyError. People may be getting the KeyError if the JSON structure has a top level object holding the array of the rows of data (this is considered a JSON best practice). Assuming a top level object called 'data', you would change only two lines of code of GeekSambhu's solution.

    writer.writerow(_json['data'][0].keys()) # header row
    for row in _json['data']:

提交回复
热议问题