Add tool that turns CSV into JSON.

This commit is contained in:
Philipp Winter 2019-07-16 10:37:19 -07:00
parent 368ba7094c
commit 5253e62ae1
No known key found for this signature in database
GPG Key ID: 0FD95F1D3A597A48
1 changed files with 23 additions and 0 deletions

23
tools/csv2json.py Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env python3
import sys
import csv
import json
def convert(file_name):
content = []
with open(file_name, "r") as f:
for line in csv.DictReader(f):
content.append(line)
print(json.dumps(content))
return 0
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: {} FILE_NAME".format(sys.argv[0]), file=sys.stderr)
sys.exit(1)
sys.exit(convert(sys.argv[1]))