Skip to content

Instantly share code, notes, and snippets.

@josuecau
Last active May 26, 2018 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josuecau/e05f953f7db72d2cacd3296d6ae77f12 to your computer and use it in GitHub Desktop.
Save josuecau/e05f953f7db72d2cacd3296d6ae77f12 to your computer and use it in GitHub Desktop.
Convert JSON to CSV using jq(1)
#!/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