Giles Dring

Welcome to my personal website. Who am I again?

Making a CSV with jq

I’m finding jq to be a really useful tool for dealing with JSON formatted data.

I came across this Stack Overflow answer for creating a CSV from any array of JSON objects.

jq -r '
  | add
  | unique
) as $cols
| map(
  . as $row
  | $cols
  | map($row[.])
) as $rows
| $cols, $rows[] | @csv'
Published on .