Skip to content

Instantly share code, notes, and snippets.

@lasergoat
Created September 15, 2017 17:18
Show Gist options
  • Save lasergoat/c8148e766441c9e5abc5ab39bc76913e to your computer and use it in GitHub Desktop.
Save lasergoat/c8148e766441c9e5abc5ab39bc76913e to your computer and use it in GitHub Desktop.
convert a csv to json
#!/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 "]"
@lasergoat
Copy link
Author

lasergoat commented Sep 15, 2017

Usage:

download script, save as convert.py
save your customer xls as data.csv

python convert.py | pbcopy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment