Skip to main content
1 of 2
TJR
  • 3.8k
  • 8
  • 40
  • 42

The following filter is slightly different in that it will ensure every value is converted to a string. (Note: use jq 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) 

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(.) 
TJR
  • 3.8k
  • 8
  • 40
  • 42