How to select with jq in an array of values?

106 views Asked by At

I want to select elements >= 3 in an array like [2, 4, 3] with jq, how do I do it?

I have found answers when the array contains objects (e.g [{Name:"a", Age:2} ...]}) with things like select (.Age >= 2) but I don't know how to refer to values

1

There are 1 answers

2
peak On BEST ANSWER

Use ..

If you want to retain the array structure, you could use map(select(_)), e.g.

jq -n '[2, 4, 3] | map(select(. >= 3))'

If you just want the values, you could consider:

jq '.[] | select(. >= 3)' <<< '[2, 4, 3]'