I am reading the jq
manual and it says, that
and -
operations on number should "just work". However, I can't seem to be able to use them in almost any operation, for example, in object construction
Given input.json
as {"a": 4}
this command:
jq "6-.a" input.json
produces
2
but this command:
jq "{b: 6-.a}" input.json
produces
jq: error: syntax error, unexpected '-', expecting '}' (Windows cmd shell quoting issues?) at <top-level>, line 1:
{b: 6-.a}
jq: 1 compile error
How to work this around? Thanks
CodePudding user response:
When constructing objects with expressions as key or value, the expression needs to be surrounded by parentheses:
jq "{b: (6-.a)}" input.json
{
"b": 2
}