Created
November 4, 2010 17:45
-
-
Save eyeseast/662844 to your computer and use it in GitHub Desktop.
Dump a CSV file to a JSON string
This file contains 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 | |
def convert(fn, outfile): | |
""" | |
Open a filename, read it as CSV, | |
dump out a string of JSON to an outfile | |
""" | |
with open(fn) as f: | |
reader = csv.DictReader(f) | |
table = [row for row in reader] | |
outfile.write(json.dumps(table)) | |
if __name__ == "__main__": | |
import sys | |
convert(sys.argv[1], sys.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment