Converting JSON to CSV
Reading a JSON File
import json
# Replace "your-file.json" with your JSON file name
with open("your-file.json") as f:
json_data = json.load(f)Writing a CSV File
import csv
# Replace "new-csv-file.csv" with your desired output file name
with open("new-csv-file.csv", "w") as f:
writer = csv.writer(f)
# Write header row of CSV file based on first case in list
writer.writerow(json_data[0].keys())
# Iterate through case list to write CSV rows
for case in json_data:
writer.writerow(case.values())Picking Specific Fields
Last updated