jq "object cannot be tsv-formatted, only array" error when making table from json data jq "object cannot be tsv-formatted, only array" error when making table from json data json json

jq "object cannot be tsv-formatted, only array" error when making table from json data


A fixed version might look like:

jq -rn '# Assign the list of fields to a variable["NAME","NODE","SOURCE IP","SOURCE PORT","DESTINATION IP","DESTINATION PORT","GATEWAY IP","GATEWAY PORT"] as $fields |(  $fields,                        # emit the list as a header  ($fields | map(length*"-")),    # print separators below each header  (inputs | .[] | [.name, .node, .s_ip, .s_port, .d_ip, .d_port, .pif_ip, .pif_port])) | @tsv' <<<"$s" # where s is a string with your JSON content.

...which emits as output, for your input (without any reformatting to align the tabs):

NAME    NODE    SOURCE IP   SOURCE PORT DESTINATION IP  DESTINATION PORT    GATEWAY IP  GATEWAY PORT----    ----    ---------   ----------- --------------  ----------------    ----------  ------------mike1   c04 10.244.7.235    38558   129.12.34.567   22  129.23.45.678   11019fhlb-test   c04 10.244.7.20 49846   129.98.76.543   22  129.87.65.432   23698

The immediate bug was the inclusion of .[] in (.[], map(length*"-")) -- the first part of that is pointless, and does nothing but insert your map contents (which isn't valid in TSV content, not being a list) into the data stream.