Created
October 16, 2023 18:56
-
-
Save wcoder/0b868ea336d0a9b75133ef5b69ddc0af to your computer and use it in GitHub Desktop.
Export CSV spreadsheets from Google docs and convert to JSON with formatting
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
#!/bin/bash | |
DOC_ID='' | |
SHEET_ID=0 | |
TMP_FILE='temp.csv' | |
OUTPUT_FILE='result.json' | |
# export csv | |
curl -L "https://docs.google.com/spreadsheets/d/$DOC_ID/export?format=csv&gid=$SHEET_ID" -o $TMP_FILE | |
# replace first line (optional) | |
#sed -i '' '1 s/^.*$/name,id/' $TMP_FILE | |
# convert to json | |
cat $TMP_FILE | python3 -c 'import csv, json, sys; print(json.dumps([r for r in csv.DictReader(sys.stdin)], ensure_ascii=False, indent=2))' > $OUTPUT_FILE | |
# cleanup | |
rm $TMP_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment