Skip to content

Instantly share code, notes, and snippets.

@KrazyADM
Created March 10, 2015 13:43
Show Gist options
  • Save KrazyADM/cbeeb98d08c9247c58b2 to your computer and use it in GitHub Desktop.
Save KrazyADM/cbeeb98d08c9247c58b2 to your computer and use it in GitHub Desktop.
import fileinput
import json
import csv
import sys
l = []
for line in fileinput.input():
l.append(line)
myjson = json.loads(''.join(l))
keys = {}
for i in myjson:
for k in i.keys():
keys[k] = 1
mycsv = csv.DictWriter(sys.stdout, fieldnames=keys.keys(),
quoting=csv.QUOTE_MINIMAL)
mycsv.writeheader()
for row in myjson:
mycsv.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment