JSON format files are hard to see. I want to convert to CSV or EXCEL. Share how to solve your worries.
In this article, I will introduce the conversion method of Json file using Python using Python and the conversion tool that can be done based on the WEB.
It's very easy to use.
--Change the "Json file name you want to convert" in the program to the Json file name you put in 1.
--Please put the word written at the beginning of the Json file in "The word written at the beginning when you open the Json file".
If the Json file starts like {" results ": [{" acl ": {" * ": {" read ": true, ...
, please enter "results" in this case.
--Change the "File name you want to output" in the program to the file name you want to output.
ConvertJsonToCsv.py
#-*-coding:utf-8-*-
################################################
#Purpose: Convert Json files to CSV.
################################################
import json
import csv
#Load JSON file
json_dict = json.load(open('Json file name you want to convert.json', 'r', encoding="utf_8_sig"))
#Extraction of list of dict
target_dicts = json_dict['The first word written when you open the Json file']
with open('File name you want to output.csv', 'w', encoding="utf_8_sig") as f:
#Dialect registration
csv.register_dialect('dialect01', doublequote=True, quoting=csv.QUOTE_ALL)
#DictWriter creation
writer = csv.DictWriter(f, fieldnames=target_dicts[0].keys(), dialect='dialect01')
#Write to CSV
writer.writeheader()
for target_dict in target_dicts:
writer.writerow(target_dict)
If it's okay to send the file to the server, I think it's easier to use this method.
WEB service that can convert Json files to CSV online
Recommended Posts