Created
May 18, 2015 07:52
-
-
Save spikeekips/b4ec5911b8c3d608b491 to your computer and use it in GitHub Desktop.
Convert csv to json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| import csv | |
| import pprint | |
| import json | |
| import sys | |
| f = sys.argv[1] | |
| headers = list() | |
| with open(f, 'rb') as f: | |
| datas = list() | |
| reader = csv.reader(f) | |
| for i, row in enumerate(reader): | |
| if i == 0: | |
| headers = range(len(row)) | |
| continue | |
| data = zip(headers, row) | |
| datas.append(data) | |
| print json.dumps(datas, ensure_ascii=True,) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment