How can I convert my JSON to CSV using jq? How can I convert my JSON to CSV using jq? json json

How can I convert my JSON to CSV using jq?


Building upon Joe Harris' answer, you can use the @csv filter so that strings are properly quoted and escaped when necessary :

jq -r '[.case, .custom."speech invoked", .custom."input method"] | @csv'


Using perl wasn't a good solution for me but after a bit of trial and error I figured out you can do it with just jq using the join() operator.

First make an array of the output you need, then join the array elements using commas.

jq -r '[.case, .custom."speech invoked", .custom."input method"] | join(", ")'

Enjoy. :)


Using jq, you can use this filter:

with_entries(select(.key != "custom")) + .custom    | to_entries    | map(.key), map(.value)    | @csv

Just note that written this way, the "custom" properties will always be written in the end, no matter what order the properties are in.