Skip to content

Instantly share code, notes, and snippets.

@shtrom
Last active March 17, 2021 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shtrom/c14910075966cd600756d6b697518696 to your computer and use it in GitHub Desktop.
Save shtrom/c14910075966cd600756d6b697518696 to your computer and use it in GitHub Desktop.
Convert an NDJSON file of similarly-formatted object to a CSV file
#!/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