Skip to content

Instantly share code, notes, and snippets.

@eyeseast
Created November 4, 2010 17:45
Show Gist options
  • Save eyeseast/662844 to your computer and use it in GitHub Desktop.
Save eyeseast/662844 to your computer and use it in GitHub Desktop.
Dump a CSV file to a JSON string
#!/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