Мой простой способ решить эту проблему:
Создайте новый файл Python, например: json_to_csv.py
Добавьте этот код:
import csv, json, sys
#if you are not using utf-8 files, remove the next line
sys.setdefaultencoding("UTF-8")
#check if you pass the input file and output file
if sys.argv[1] is not None and sys.argv[2] is not None:
fileInput = sys.argv[1]
fileOutput = sys.argv[2]
inputFile = open(fileInput)
outputFile = open(fileOutput, 'w')
data = json.load(inputFile)
inputFile.close()
output = csv.writer(outputFile)
output.writerow(data[0].keys()) # header row
for row in data:
output.writerow(row.values())
После добавления этот код, сохраните файл и запустите на терминале:
python json_to_csv.py input.txt output.csv
blockquote>Надеюсь, это поможет вам.
SEEYA!