gpt4 book ai didi

jmespath - 根据多个键/值对的存在来过滤输出

转载 作者:行者123 更新时间:2023-12-03 06:39:31 24 4
gpt4 key购买 nike

使用 JMESPath,是否可以根据输入中是否存在多个键/值对来过滤输出?

从下面的示例 JSON 中,我想要做的是仅提取 Tags 中包含这些键/值对的对象 -

Environment / ABC
Project / Project2

我能得到的最接近的是选择一个匹配的标签,但我也需要对象的其余部分,并且我还需要与其他键/值对匹配 -

Stacks[*].Tags[?Key=='Environment' && Value=='ABC']

这是一些 JSON 输入示例 -

{
"Stacks": [
{
"StackId": "abc123",
"Tags": [
{
"Value": "Project 1",
"Key": "Project"
},
{
"Value": "ABC",
"Key": "Environment"
}
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack1",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
},
{
"StackId": "xyz123",
"Tags": [
{
"Value": "Project 1",
"Key": "Project"
},
{
"Value": "XYZ",
"Key": "Environment"
}
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack2",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
},
{
"StackId": "asd123",
"Tags": [
{
"Value": "Project 2",
"Key": "Project"
},
{
"Value": "ABC",
"Key": "Environment"
}
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack3",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
}
]
}

这是我需要的输出 -

{
"StackId": "asd123",
"Tags": [
{
"Value": "Project 2",
"Key": "Project"
},
{
"Value": "ABC",
"Key": "Environment"
}
],
"CreationTime": "2016-07-20T14:49:27.891Z",
"StackName": "TestStack3",
"NotificationARNs": [],
"StackStatus": "CREATE_COMPLETE",
"DisableRollback": false
}

最佳答案

您可以使用嵌套过滤器:

堆栈[?标签[?值=='ABC' && 键=='环境']]

关于jmespath - 根据多个键/值对的存在来过滤输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41503405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com