Skip to content

Instantly share code, notes, and snippets.

@multimeric
Created September 11, 2016 13:04
Show Gist options
  • Save multimeric/623114a2601b85355fb88b41107a4fd1 to your computer and use it in GitHub Desktop.
Save multimeric/623114a2601b85355fb88b41107a4fd1 to your computer and use it in GitHub Desktop.
Bash script to convert mtgjson's AllCards.json into a csv format
# Download the database
wget https://mtgjson.com/json/AllCards.json.zip
# Unzip it
unzip AllCards.json.zip
# Convert to CSV
jq -r 'to_entries[] | [.key, (.value | tostring ) ] | @csv' AllCards.json > AllCards.csv
# Load into postgres
# Note that you'll need need to set the correct login details to the psql command (e.g. change it to `psql -U postgres`)
echo "CREATE TABLE IF NOT EXISTS mtgj(name text, data json); COPY mtgj(name, data) FROM '`pwd`/AllCards.csv' (FORMAT csv)" \
| psql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment