Skip to content

Instantly share code, notes, and snippets.

@ariscop ariscop/json2csv
Last active Sep 12, 2015

Embed
What would you like to do?
#!/usr/bin/env python3
import sys
import json
data = []
with open(sys.argv[1], "r", encoding="utf-8") as f:
data = json.loads(f.read(), encoding="utf-8")
keys = data[0].keys()
print("\t".join(keys))
for obj in data:
print("\t".join([str(obj[key]) for key in keys]))
@aji

This comment has been minimized.

Copy link

commented Sep 12, 2015

#!/usr/bin/env python3
import sys
import json
import calendar
import time

data = []
with open(sys.argv[1], "r", encoding="utf-8") as f:
    data = json.loads(f.read(), encoding="utf-8")

keys = list(data[0].keys())

print("\t".join(keys + ['long_ago']))
for obj in data:
    row = [str(obj[key]) for key in keys] + [str(calendar.timegm(time.gmtime()))]
    print("\t".join(row))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.