Created
September 15, 2017 17:18
-
-
Save lasergoat/c8148e766441c9e5abc5ab39bc76913e to your computer and use it in GitHub Desktop.
convert a csv to json
This file contains hidden or 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
#!/usr/bin/python | |
import csv | |
import json | |
header = [] | |
results = [] | |
print "[" | |
with open('data.csv', 'rb') as f: | |
reader = csv.reader(f) | |
for row in reader: | |
if len(header) > 0: | |
datarow = {} | |
for key, value in (zip(header,row)): | |
datarow[key] = value | |
print json.dumps(datarow) | |
print "," | |
else: | |
header = row | |
print "]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
download script, save as convert.py
save your customer xls as
data.csv
python convert.py | pbcopy