The following filter is slightly different in that it will ensure every value is converted to a string. (Note: use jqjq 1.5+)
# For an array of many objects jq -f filter.jq (file) # For many objects (not within array) jq -s -f filter.jq (file) # For an array of many objects jq -f filter.jq [file] # For many objects (not within array) jq -s -f filter.jq [file] Filter: filter.jq
def tocsv($x): $x |(map(keys) |add |unique |sort ) as $cols |map(. as $row |$cols |map($row[.]|tostring) ) as $rows |$cols,$rows[] | @csv; tocsv(.)