Skip to content

Instantly share code, notes, and snippets.

@peasead
Created June 15, 2021 18:57
Show Gist options
  • Save peasead/950b4eb27bf9123bbc79190f939a9417 to your computer and use it in GitHub Desktop.
Save peasead/950b4eb27bf9123bbc79190f939a9417 to your computer and use it in GitHub Desktop.
Convert a CSV file to NDJSON using Python
# python3 csv-to-ndjson.py
# pip3 install csv json
import csv
import json
csvfile = open('in.csv', 'r')
jsonfile = open('out.ndjson', 'w')
fieldnames = ("field1","field2","field3")
reader = csv.DictReader( csvfile, fieldnames)
for row in reader:
json.dump(row, jsonfile)
jsonfile.write('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment