Created
October 5, 2013 09:51
-
-
Save hanjianwei/6838951 to your computer and use it in GitHub Desktop.
CSV to JSON converter
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/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