Home > Back-end >  Store Json data to JSON file and save them in the CSV file
Store Json data to JSON file and save them in the CSV file

Time:12-13

I tried this way but did not work

   with open("data.json", "a", encoding='utf-8') as f:
      json.dump(data,  f,ensure_ascii=False, indent=4 )

But this problem occurs

enter image description here

#2

I want to convert from json to CSV

An example of what I want

enter image description here

Please tell me if this is possible

CodePudding user response:

You can't append JSON files together into a new JSON, because of the nature of the JSON format.

Instead of writing each object individually to the JSON file, you should collect all of the objects into a list, and write the list to the JSON file:

lst = []
for data in ...:
    lst.append(data)

with open("data.json", "w", encoding='utf-8') as f:
    #                   ^ notice "a" was changed to "w" here
    json.dump(lst, f, ensure_ascii=False, indent=4)

CodePudding user response:

Both can be done with pandas

  • Related