Last active
March 14, 2022 00:13
-
-
Save beugley/b71784dc96627256cf86336b9b7f5cb2 to your computer and use it in GitHub Desktop.
Python snippet to convert a json file to csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import json | |
import csv | |
fin = sys.argv[1] | |
fout = os.path.splitext(fin)[0]+'.csv' | |
with open(fin) as f: | |
j = [json.loads(i) for i in f.readlines()] | |
with open(fout,"wb") as f: | |
csvwriter = csv.writer(f, lineterminator = '\n') | |
csvwriter.writerow(j[0].keys()) | |
for row in j: | |
csvwriter.writerow(row.values()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment