0xF4D3C0D3
0xF4D3C0D3

Reputation: 827

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

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?

Upvotes: 3

Views: 698

Answers (1)

pmf
pmf

Reputation: 36088

Is this what you are looking for?

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

Upvotes: 2

Related Questions