Skip to content

Instantly share code, notes, and snippets.

@bretton
Created April 12, 2023 09:44
Show Gist options
  • Save bretton/7251f959dd29da6b8bb2fe71a901aa26 to your computer and use it in GitHub Desktop.
Save bretton/7251f959dd29da6b8bb2fe71a901aa26 to your computer and use it in GitHub Desktop.
Bash and python one-liner to convert CSV to JSON

Best method to convert CSV to JSON in bash one-liner

wget http://host/file.csv

# csv to json in python, requires a header row
cat file.csv | python -c 'import csv, json, sys; print(json.dumps([dict(r) for r in csv.DictReader(sys.stdin)]))' > file.json

cat file.json |jq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment