Last active
May 26, 2018 09:27
-
-
Save josuecau/e05f953f7db72d2cacd3296d6ae77f12 to your computer and use it in GitHub Desktop.
Convert JSON to CSV using jq(1)
This file contains 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
#!/usr/bin/env bash | |
# | |
# Convert JSON to CSV using jq(1) | |
# Source: https://stackoverflow.com/a/32967407 | |
[ $# -ge 1 -a -f "$1" ] && input="$1" || input="-" | |
jq -r '(.[0] | keys_unsorted) as $keys | $keys, map([.[ $keys[] ]])[] | @csv' $input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment