In the section:
python -c "import csv,json;print json.dumps(list(csv.reader(open('csv_file.csv'))))"I tried the code in the paragraph with both Python 2 and 3(with modification), sample:
a,b,c,d,e1,2,3,4,5f,w,e,r,t`,1,2,3,4
it returns like:
[["a", "b", "c", "d", "e"], ["1", "2", "3", "4", "5"], ["f", "w", "e", "r", "t"], ["`", "1", "2", "3", "4"]]
Not seems like JSON. So maybe it's wrong.
However, I don't know the sample of the CSV and output in the paragraph, so I didn't create a pull request.
I have code which works, but not in one line:
importcsvimportjsondefcsv_to_json(file_path):
ret_list= []
withopen(file_path, 'r') asf:
csv_list=list(csv.reader(f))
forcolincsv_list[1:]:
ret_list.append(dict(zip(csv_list[0], col)))
returnjson.dumps(ret_list)
print(csv_to_json('csv_file.csv'))returns (with CSV above):
[{"a": "1", "b": "2", "c": "3", "d": "4", "e": "5"}, {"a": "f", "b": "w", "c": "e", "d": "r", "e": "t"}, {"a": "`", "b": "1", "c": "2", "d": "3", "e": "4"}]
In the section:
python -c "import csv,json;print json.dumps(list(csv.reader(open('csv_file.csv'))))"I tried the code in the paragraph with both Python 2 and 3(with modification), sample:
it returns like:
Not seems like JSON. So maybe it's wrong.
However, I don't know the sample of the CSV and output in the paragraph, so I didn't create a pull request.
I have code which works, but not in one line:
returns (with CSV above):