Skip to content

Instantly share code, notes, and snippets.

@annacruz
Created May 30, 2017 17:25
Show Gist options
  • Save annacruz/23bf1b514a318cb34230dbb668c690dc to your computer and use it in GitHub Desktop.
Save annacruz/23bf1b514a318cb34230dbb668c690dc to your computer and use it in GitHub Desktop.
Parsing csv files with tab delimiter to JSON
import csv
import json
csvfile = open('file1.csv', 'r')
jsonfile = open('file2.json', 'w')
fieldnames = ("firstname", "lastname", "phone", "birthdate")
reader = csv.DictReader( csvfile, fieldnames, delimiter='\t')
for row in reader:
json.dump(row, jsonfile)
jsonfile.write('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment