Created
August 9, 2019 10:24
-
-
Save gwillem/86302f47a159a7164a4ddcc58cabff9f to your computer and use it in GitHub Desktop.
This file contains 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
#!/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