The assignment operators are somewhat tricky to use. This may be mostly a matter of documentation...
Issues:
- users often miss the fact that the LHS expression is supposed to be a path expression matching paths in
.
= and |= have different semantics besides |= passing the value at the LHS paths to the RHS expression. Compare jq -n '(.a, .b, .c) = (1,2,3)' to jq -n '(.a, .b, .c) |= (1,2,3)'.
The first issue is easy enough to handle in documentation.
The second issue is difficult to "fix" without risking breaking jq programs. Since |= is supposed to modify whatever value is found at the LHS, only one of the RHS expressions' outputs can be used as the final value -- there is just no question of making |= work like =. One reason that we can't make |= work like = is that while the RHS in the = case will produce the same outputs for all paths named in the LHS, the RHS in the |= absolutely can produce different sets of outputs for each path as the RHS gets a possibly-different input for each path in .. At best we could make = work like |=, but ='s behavior as to RHS generator expressions seems to be just too useful, and thus likely to be depended upon. This too, then, seems like a job for documentation.
Unless other issues crop up, we should close this one (perhaps after tweaking the docs).
The assignment operators are somewhat tricky to use. This may be mostly a matter of documentation...
Issues:
.=and|=have different semantics besides|=passing the value at the LHS paths to the RHS expression. Comparejq -n '(.a, .b, .c) = (1,2,3)'tojq -n '(.a, .b, .c) |= (1,2,3)'.The first issue is easy enough to handle in documentation.
The second issue is difficult to "fix" without risking breaking jq programs. Since
|=is supposed to modify whatever value is found at the LHS, only one of the RHS expressions' outputs can be used as the final value -- there is just no question of making|=work like=. One reason that we can't make|=work like=is that while the RHS in the=case will produce the same outputs for all paths named in the LHS, the RHS in the|=absolutely can produce different sets of outputs for each path as the RHS gets a possibly-different input for each path in.. At best we could make=work like|=, but='s behavior as to RHS generator expressions seems to be just too useful, and thus likely to be depended upon. This too, then, seems like a job for documentation.Unless other issues crop up, we should close this one (perhaps after tweaking the docs).