#!/usr/bin/python

import json, sys

if len(sys.argv) > 1:
    first_argument = sys.argv[1]
    print("The first command-line argument is:", first_argument)
else:
    print("No command-line arguments provided.")
    exit()

sep = '\t'
dd = open(sys.argv[1],encoding='utf-8').read()
if not sep in dd:
    print('separator',',')
    sep = ','

dd = dd.replace('"','\\"')

f = list(map(lambda i: i.split(sep),dd.splitlines()))
j = json.dumps([ dict(zip(f[0], l))  for l in f[1:] ], indent=2).encode().decode('unicode-escape')
open(sys.argv[1]+'.json','w', encoding="utf-8").write(j)

input("press enter")

