具有多个匹配项的 JMESPath JSON 过滤器
我有一个看起来有点像这样的 json 块(你从 AWS 中猜到了吗)
I have a json block that looks a bit like this (have you guessed from AWS)
{ "Vpcs":[
{
"VpcId":"vpc-blabla1",
"OtherKey":"Value"
},
{
"VpcId":"vpc-blabla2",
"OtherKey":"Value"
},
{
"VpcId":"vpc-blabla3",
"OtherKey":"Value"
},
{
"VpcId":"vpc-blabla4",
"OtherKey":"Value"
}]
}
我想使用 JMESPath 来获取 vpc-blabla1 和 vpc-blabla3 的 OtherKey 值(示例,可以是任何 vpc-id 列表)
I want to use JMESPath to get the OtherKey value for vpc-blabla1 and vpc-blabla3 (Examples, could be any list of vpc-id)
我可以使用 JMESpath 过滤器获取 blabla1
I can get blabla1 with JMESpath filter
Vpcs[?VpcId=='blabla1'].OtherKey
但是我找不到多个值的语法?我试过 Or 语法 ||和复合语法 |但两者都不起作用?- 有关我尝试过的内容,请参见下文.
But I can't find the syntax for multiple values? I have tried the Or syntax || and the composite syntax | but neither works? - See below for things I have tried.
Vpcs[?VpcId=='blabla1' || 'blabla1'].OtherKey
Vpcs[?VpcId=='blabla1' || ?VpcId=='blabla1'].OtherKey
Vpcs[(?VpcId=='blabla1') || (?VpcId=='blabla1')].OtherKey
Vpcs[?VpcId=='blabla1' | ?VpcId=='blabla1'].OtherKey
有什么建议吗?这是可能的,还是我必须一次收集一个结果集并重新组合我想要的结果?
Any suggestions? Is this possible or am I going to have to gather one result set at a time and recombine the results I want?
multiple 的一般语法是 [?expr1 ||expr2
] 所以在你的情况下,你可以使用:
The general syntax for multiple is [? expr1 || expr2
] so in your case, you can use:
Vpcs[?VpcId=='vpc-blabla1' || VpcId=='vpc-blabla2'].OtherKey
另一种选择,如果您要搜索的 VPC id 很多,您也可以说:
Another option, if you have many VPC ids you're search for, you can also say:
Vpcs[?contains(`["vpc-blabla1", "vpc-blabla2"]`, VpcId)].OtherKey