Skip to content

Instantly share code, notes, and snippets.

@alextanhongpin
Created September 7, 2017 09:48
Show Gist options
  • Save alextanhongpin/8ae1a734e5c9507b4857ef3443d0983d to your computer and use it in GitHub Desktop.
Save alextanhongpin/8ae1a734e5c9507b4857ef3443d0983d to your computer and use it in GitHub Desktop.
CSV to JSON converter
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