Good afternoon sirs
I already know how to convert a csv file to json, however I am now unable to get each csv line saved in a different json.
Example:
Row 1: Json1.json
Row 2: Json2.json
The name of each file would be the fieldName of each row
Could someone give me a light on this?
The code follows:
import csv
import json
# Open the CSV
f = open( '/path/to/filename.csv', 'rU' )
# Change each fieldname to the appropriate field name. I know, so difficult.
reader = csv.DictReader( f, fieldnames = ( "fieldname0","fieldname1","fieldname2","fieldname3" ))
# Parse the CSV into JSON
out = json.dumps( [ row for row in reader ] )
print "JSON parsed!"
# Save the JSON
f = open( '/path/to/parsed.json', 'w')
f.write(out)
print "JSON saved!"
[ row for row in reader ]islist(reader)(do not overcomplicate your code).