Last active
March 17, 2021 02:40
-
-
Save shtrom/c14910075966cd600756d6b697518696 to your computer and use it in GitHub Desktop.
Convert an NDJSON file of similarly-formatted object to a CSV file
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 | |
import csv, ndjson, itertools, sys | |
r = ndjson.reader(sys.stdin) | |
r, rh = itertools.tee(r) | |
w = csv.DictWriter(sys.stdout, next(rh).keys()) | |
w.writeheader() | |
for d in r: | |
w.writerow(d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment