Skip to content

Instantly share code, notes, and snippets.

@hanjianwei
Created October 5, 2013 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanjianwei/6838951 to your computer and use it in GitHub Desktop.
Save hanjianwei/6838951 to your computer and use it in GitHub Desktop.
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