Question
What is the data type of the JQ comma filter?
Background
I get Cannot iterate over number error when trying to feed the output of the comma filter.
$ printf '{"ika":5,"uni":3}' | jq '.ika, .uni | .'
5
3
$ printf '{"ika":5,"uni":3}' | jq '.ika, .uni | . | add'
jq: error (at <stdin>:0): Cannot iterate over number (5)
To get around, need to convert to an array explicitly.
$ printf '{"ika":5,"uni":3}' | jq '[ .ika, .uni ] | . | add'
8
Clarifications
According to the JQ manual, the output of a JQ filter is a sequence of whitespace-separated JSON data
However, the output the comma filter (which is stated as one of the Basic filters) seems not to be a sequence of whitespace-separated JSON data.
Comma: ,
If two filters are separated by a comma, then the same input will be fed into both and the two filters’ output value streams will be concatenated in order: first, all of the outputs produced by the left expression, and then all of the outputs produced by the right. For instance, filter .foo, .bar, produces both the “foo” fields and “bar” fields as separate outputs.
jq filters run on a stream of JSON data. The input to jq is parsed as a sequence of whitespace-separated JSON values which are passed through the provided filter one at a time. The output(s) of the filter are written to standard out, again as a sequence of whitespace-separated JSON data.
It’s important to remember that every filter has an input and an output. Even literals like “hello” or 42 are filters - they take an input but always produce the same literal as output. Operations that combine two filters, like addition, generally feed the same input to both and combine the results.
So what is the output of comma filter? If is it JSON data as the JQ manual says? I assume, if it is to be a JSON, then should it be an array?
[5, 3]
Update
Based on the answers:
In jq expressions such as P|Q, the filter Q processes each item in the stream produced by P one at a time. In the invocation jq P, each item in the STDIN stream is processed by P one at a time.
$ printf '{"ika":5,"uni":3}' | \
jq '.ika, .uni' | \
jq '"JQ is processing the \(input_line_number) th line whose input value is \(.)"'
"JQ is processing the 1 th line whose input value is 5"
"JQ is processing the 2 th line whose input value is 3"
