Skip to content

Instantly share code, notes, and snippets.



Created Aug 1, 2017
What would you like to do?
Script that takes an JSON-blob on stdin containg an array of objects, and outputs a CSV.
#!/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'
>&2 echo "\033[31mERROR: $(basename $0) requires jq\033[0m"
exit 127
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.