I have the following code that transforms a .csv file to a .json one. Because I have multiple csv records, and I will need to operate on multiple json objects, I was thinking of creating an array. The resulting file looks good, EXCEPT that the last record has a trailing comma. I have been trying to figure out how to not include that comma, but have not been able to do so.
csvfile = open('file.csv','r')
jsonfile = open('file.json','w')
reader = csv.DictReader(csvfile)
jsonfile.write('[')
for row in reader:
json.dump(row, jsonfile)
jsonfile.write(',')
jsonfile.write('\n')
jsonfile.write(']')