Created
September 7, 2017 09:48
-
-
Save alextanhongpin/8ae1a734e5c9507b4857ef3443d0983d to your computer and use it in GitHub Desktop.
CSV to JSON converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import json | |
with open('data/ref_language.csv') as csvfile: | |
reader = csv.DictReader(csvfile) | |
fieldnames = reader.fieldnames | |
output = [] | |
for row in reader: | |
j = {} | |
for i, _ in enumerate(fieldnames): | |
j[fieldnames[i]] = row[fieldnames[i]] | |
output.append(j) | |
with open('data/ref-language.json','w') as jsonfile: | |
jsonfile.write(json.dumps(output)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment