Home > other >  `in` operator in jq. But, it doesn't work as I want
`in` operator in jq. But, it doesn't work as I want

Time:10-13

with input like this:

{"type": "mammal", "value": "lion"}
{"type": "reptile", "value": "snake"}
{"type": "insect", "value": "fly"}
{"type": "mammal", "value": "chicken"}

I could get what I want with select(.type=="mammal" or .type=="reptile"). But this is simplified version, as you can expect, this could be too verbose easily.

So I want to do the same with more succinct way like select(.type in ["mammal", "reptile"]). I know that it's not valid though, it's a pseudo code and you could understand my intention.

I tried several things with in/1 and index/1, but I couldn't be happy... What should I do?

CodePudding user response:

Is this what you are looking for?

select(.type | IN("mammal","reptile"))
  • Related