Last active
July 7, 2020 23:55
-
-
Save sshh12/9b81975505a48855991949d6a57a9d19 to your computer and use it in GitHub Desktop.
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
import json | |
import sys | |
import csv | |
def main(fn): | |
with open(fn, 'r', newline='') as csvfile: | |
reader = csv.DictReader(csvfile) | |
rows = [dict(row) for row in reader] | |
with open('data.json', 'w') as jsonfile: | |
jsonfile.write(json.dumps(rows, indent=2)) | |
if __name__ == "__main__": | |
args = sys.argv | |
if len(args) == 2: | |
fn = args[1] | |
else: | |
fn = input('csv filename > ') | |
main(fn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python3 csv-to-json.py my.csv