jq
jq copied to clipboard
misleading statement in the manual
The manual states:
jq has a few operators of the form a op= b, which are all equivalent to a |= . op b.
However this is not true; a op= b
is not always equal to a |= . op b
in function; more accurately it's equal to b as $rhs | a |= . op $rhs
.
For instance, when the RHS of op=
is a stream of n
values, the result is also a stream of n
values; in the same scenario |= . op
yields a single value. Compare these:
$ jq -cn '.a += (1,2,3)'
{"a":1}
{"a":2}
{"a":3}
$
$ jq -cn '.a |= . + (1,2,3)'
{"a":1}
So, that statement is misleading.
Yes, it should say they are equivalent to (b as $b | a |= . op $b)
.