How do I use C math functions in JQ that take more than one argument? There are no examples in the manual. All it says is:
C math functions that take a single input argument (e.g.,
sin()
) are available as zero-argumentjq
functions. C math functions that take two input arguments (e.g.,pow()
) are available as two-argument jq functions that ignore.
C math functions that take three input arguments are available as three-argument jq functions that ignore.
I've figured out how to single input argument functions, which are implemented as zero-argument jq functions:
> echo '{"a": 10.12}' | jq '.a | floor'
10
How do I use something like pow
?
What does the manual mean by "jq functions that ignore .
"? Do they ignore what's piped in, in the sense that they don't take it as an argument, in contrast to the one input argument case where the argument is taken just from the pipe?
It's simple, just separate function arguments by ;
:
> echo '{"a": 10.12}' | jq '. | pow(.a;.a)'
20051775181.748566
Regarding the meaning of jq functions that ignore .
:
It appears that in the case of single-input-argument functions, like floor
, what actually happens is that the default argument .
is used, thus no need to actually mention any argument.
In the case of 2 or more input arguments, that of course doesn't do anymore, so no default argument is applied and both argument have to be explicitly passed.