Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active October 4, 2021 14:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joyrexus/7407781 to your computer and use it in GitHub Desktop.
Save joyrexus/7407781 to your computer and use it in GitHub Desktop.
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)
#!/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment