Skip to content

Instantly share code, notes, and snippets.

@dcode
Created August 30, 2016 16:58
Show Gist options
  • Save dcode/61626e5aaa78f37183114f13113c12fe to your computer and use it in GitHub Desktop.
Save dcode/61626e5aaa78f37183114f13113c12fe to your computer and use it in GitHub Desktop.
Useful for mapping JSON to CSV when each of the records have the same structure. You can put this into a script and `chmod +x` it.
#!/usr/local/bin/jq -s -r -f
( map(keys) | add | unique ) as $cols |
map(. as $row | $cols | map($row[.])) as $rows |
$cols, $rows[] | @csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment