Although what you are definitely working on, it would be better to use contains . I would avoid this use as it can lead to confusion. index("blue") is 0 , and no one considers this a plausible value and can expect it to be excluded from the results.
Use this filter instead:
select(.items | contains(["blue"]))
This has the added benefit that it will work if you need elements with multiple matches, just adding more to the array. Strike>
As stated in the comments, this is not entirely correct. Strings are compared using a substring ( contains used recursively) here.
In retrospect, contains did not work as I thought. Using index works, but personally, I would not use it. There is something to figure out if there is an item in the collection by looking for its index, which I don't like. Using contains makes more sense to me, but in the light of this information in this case it will not be ideal.
Here is an alternative that should work correctly:
select([.items[] == "blue"] | any)
Or for a more scalable way, if you want to be able to match more values:
select(.items as $values | ["blue", "yellow"] | map([$values[] == .] | any) | all)
source share