Created
October 2, 2014 12:59
-
-
Save aaronthorp/15ad08b5bf9ba68c8f67 to your computer and use it in GitHub Desktop.
JSON to CSV with Python
This file contains hidden or 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 csv | |
import json | |
f = open('partscon.json', 'r') | |
x = json.loads(f.read().decode('utf-8-sig')) | |
f.close() | |
#x = json.loads(x) | |
f = csv.writer(open("partscon-final.csv", "wb+")) | |
# Write CSV Header, If you dont need that, remove this line | |
f.writerow(["timestamp", "invoice_no", "invoice_date", "entrant_name", "entrant_email", "supplier_name"]) | |
for x in x: | |
f.writerow([x["timestamp"], | |
x["invoice_no"], | |
x["invoice_date"], | |
x["entrant"]["name"], | |
x["entrant"]["email"], | |
x["supplier"]["name"]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment