Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jq: how does any() real work in array context?

Tags:

jq

jq produces unexpected results when any() is called in this context any(array[]==val)

I'm not sure how jq calculates these results:

$ jq -n '[2,2] | any( [1,2][]|. == .) '
false
$ jq -n '[2,2] | any( [2,1][]|. == .) '
false
# or
$ jq -n '[2,2] | any( [1,2][] == .) '
true
$ jq -n '[2,2] | any( [2,1][] == .) '
false

I'd expect true in all cases?

when using == in explicit expression, the results are as expected.

$ jq -n '([2,2][]) == ([1,2][])'
false
false
true
true
$ jq -n '([2,2][]) == ([2,1][])'
true
true
false
false

How can it be explained?

like image 311
Kaw Avatar asked Aug 12 '26 19:08

Kaw


1 Answers

It seems that is a bug in jq 1.6. I compiled master version which gives correct result :

$ jq --version
jq-1.6-159-gcff5336
$ jq -n '[2,2] | any( [1,2][]|. == .) '
true
$ jq -n '[2,2] | any( [2,1][]|. == .) '
true
$ jq -n '[2,2] | any( [1,2][] == .) '
true
$ jq -n '[2,2] | any( [2,1][] == .) '
true
like image 57
Philippe Avatar answered Aug 16 '26 17:08

Philippe