Created
August 1, 2017 18:43
-
-
Save yaauie/55328d2edf0c3ff374cd83302e470b03 to your computer and use it in GitHub Desktop.
Script that takes an JSON-blob on stdin containg an array of objects, and outputs a CSV.
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 sh | |
if which jq ; then | |
cat | jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv' | |
else | |
>&2 echo "\033[31mERROR: $(basename $0) requires jq\033[0m" | |
exit 127 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment