I'm converting a csv file with multiple records to a file with a json array. Solution is How to find last line in csv file when using DictReader. This works fine, except that resulting json in file has backslash (\) and double-quotes; i.e. it's escaping the strings. For example:
{"Test Name": "Basic Tcp IPerf Test", " \"Status\"": "PASS", " \"Test Start Time\"": "20190103 08:07:41.662", " \"Test End Time\"": "20190103 08:08:44.051", " \"Throughput\"": "2095.2746", " \"Jitter\"": "", " \"Packet Loss %\"": "", " \"Compute/VM\"": "SendVm (x.x.x.x)", " \"Statistics Sampling Start Time\"": "03 Jan 2019 08:07:44", " \"Statistics Sampling End Time\"": "03 Jan 2019 08:08:42", " \"Min CPU\"": "0", " \"Max CPU\"": "2", " \"Avg CPU\"": "1", " \"Avg Memory (MB)\" ": "7758"}
Is there a way to write out that json without that escaping? Code:
csvfile = open('fiile.csv','r')
jsonfile = open('file.json','w')
reader = csv.DictReader(csvfile)
jsonfile.write(json.dumps(list(reader)))