Skip to content

Instantly share code, notes, and snippets.

@aaronthorp
Created October 2, 2014 12:59
Show Gist options
  • Save aaronthorp/15ad08b5bf9ba68c8f67 to your computer and use it in GitHub Desktop.
Save aaronthorp/15ad08b5bf9ba68c8f67 to your computer and use it in GitHub Desktop.
JSON to CSV with Python
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