I'm using jq and trying to remove an element from an array based on it's value by can't figure out the syntax, it works with map but not del:
input = [10,11,12]
echo $input | jq -r 'map(select(. == 10))' returns [10]
echo $input | jq -r 'del(select(. == 10))' returns [10,11,12] not [11,12] as expected
Can someone point me in the right direction?
del is intended for deleting-by-path, not by-value:
 [10,11,12] | del(.[0]) #=> [11,12]
One way to achieve what you want is to use select:
 [10,11,12] | map(select(. != 10))
Another would be to use array subtraction:
 [10,11,12] - [10]
But that's maybe too easy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With