Skip to content

Instantly share code, notes, and snippets.

@kosho
Created April 11, 2017 00:54
Show Gist options
  • Save kosho/401244801931aa2e77014d15354e178a to your computer and use it in GitHub Desktop.
Save kosho/401244801931aa2e77014d15354e178a to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import sys
import codecs
import csv
import json
# Modify the `fieldnames` with the column names of the CSV input
fieldnames = tuple(range(200))
csvfile = open(sys.argv[1], 'rU')
reader = csv.DictReader(csvfile, fieldnames)
jsonfile=codecs.open(sys.argv[2], 'w', 'utf_8')
for row in reader:
jsonfile.write("{\"index\":{}}\n")
out = json.dumps(row, sort_keys=False, ensure_ascii=False, encoding='utf_8')
jsonfile.write(out)
jsonfile.write("\n")
csvfile.close()
jsonfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment