Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 28 lines (22 sloc) 656 Bytes
#!/usr/bin/env python3
import csv
import json
import sys
# If --parse is set, try to parse each entry as json
def parse(thing):
return json.loads(thing)
return thing
# Assume that headers are the first row
reader = csv.reader(sys.stdin, delimiter = ',' if not '--tab' in sys.argv else '\t')
headers = None
for row in reader:
if not headers:
headers = row
if '--parse' in sys.argv:
row = [parse(thing) for thing in row]
# Recombine the headers with each row (no one said this was saving space)
row = dict(zip(headers, row))
print(json.dumps(row, default = str))
You can’t perform that action at this time.