block by joyrexus 7407781

Convert csv to json

Convert a CSV (comma-separated value) file into JSON.

Usage

csv2json.py data.csv > data.json
#!/usr/bin/env python
import sys
import csv
import json

if len(sys.argv) < 2: raise SystemExit
reader = csv.DictReader(open(sys.argv[1]))
print json.dumps([row for row in reader], indent=2)

csv2json.py