Created
June 15, 2021 18:57
-
-
Save peasead/950b4eb27bf9123bbc79190f939a9417 to your computer and use it in GitHub Desktop.
Convert a CSV file to NDJSON using Python
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
# 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