jq 中的 `in` 运算符。但是,它并没有像我想要的那样工作
`in` operator in jq. But, it doesn't work as I want
输入如下:
{"type": "mammal", "value": "lion"}
{"type": "reptile", "value": "snake"}
{"type": "insect", "value": "fly"}
{"type": "mammal", "value": "chicken"}
我可以用 select(.type=="mammal" or .type=="reptile")
得到我想要的东西。但这是简化版,如您所料,这可能太冗长了。
所以我想用更简洁的方式做同样的事情,比如 select(.type in ["mammal", "reptile"])
。我知道它是无效的,它是一个伪代码,你可以理解我的意图。
我用 in/1 和 index/1 尝试了几件事,但我不满意...我该怎么办?
这是您要找的吗?
select(.type | IN("mammal","reptile"))
输入如下:
{"type": "mammal", "value": "lion"}
{"type": "reptile", "value": "snake"}
{"type": "insect", "value": "fly"}
{"type": "mammal", "value": "chicken"}
我可以用 select(.type=="mammal" or .type=="reptile")
得到我想要的东西。但这是简化版,如您所料,这可能太冗长了。
所以我想用更简洁的方式做同样的事情,比如 select(.type in ["mammal", "reptile"])
。我知道它是无效的,它是一个伪代码,你可以理解我的意图。
我用 in/1 和 index/1 尝试了几件事,但我不满意...我该怎么办?
这是您要找的吗?
select(.type | IN("mammal","reptile"))