I would like to covert a CSV to a set of JSON objects with Python, formatted in rows.
I tried this script below, put together from a couple SO answers, but this form
import csv
import json
CSV_PATH = 'file.csv'
JSON_PATH = 'demo.json'
with open(CSV_PATH, 'r') as csv_file:
reader = csv.DictReader(csv_file)
with open(JSON_PATH, 'w') as json_file:
for row in reader:
json_file.write(json.dumps(row) + '\n')
str(row)
gives the wrong kind of quotes, don't use it. You won't be able to read the file with json
.