Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CSV to JSON converter
#!/usr/bin/env python
import csv
import json
import sys
if __name__ == "__main__":
if len(sys.argv) != 2:
print "Usage: %s input" % sys.argv[0]
sys.exit(1)
with open(sys.argv[1], 'rb') as f:
reader = csv.DictReader(f, delimiter=',', quotechar='"', skipinitialspace=True)
out = json.dumps([row for row in reader])
print out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment