Skip to content

Instantly share code, notes, and snippets.

@gwillem
Created August 9, 2019 10:24
Show Gist options
  • Save gwillem/86302f47a159a7164a4ddcc58cabff9f to your computer and use it in GitHub Desktop.
Save gwillem/86302f47a159a7164a4ddcc58cabff9f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# jsonline to csv converter for Andy
import csv
import json
import sys
if len(sys.argv) < 2:
print("Use {} <file.jsonline>".format(sys.argv[0]))
sys.exit(1)
writer = None
with open(sys.argv[1]) as fh:
for line in fh:
blob = json.loads(line.strip())
if not writer:
writer = csv.DictWriter(sys.stdout, fieldnames=blob.keys())
writer.writeheader()
writer.writerow(blob)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment