Thomas
Thomas

Reputation: 8978

How to select with jq in an array of values?

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

Upvotes: 0

Views: 98

Answers (1)

peak
peak

Reputation: 117077

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]'

Upvotes: 0

Related Questions