Skip to content

Instantly share code, notes, and snippets.

@defvol
Created August 21, 2018 20:38
Show Gist options
  • Save defvol/123a004d5d4358b63741173180c46b46 to your computer and use it in GitHub Desktop.
Save defvol/123a004d5d4358b63741173180c46b46 to your computer and use it in GitHub Desktop.
Simple python script to transform CSV to JSON
# usage: python csv-to-json.py the.csv
# based on https://stackoverflow.com/questions/3428532/how-to-import-a-csv-file-using-python-with-headers-intact-where-first-column-is#3428562
import csv
import json
import sys
csvfile = open(sys.argv[1], 'r')
reader = csv.DictReader(csvfile)
out = json.dumps( [ row for row in reader ] )
sys.stdout.write(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment