我需要在 AWS Step Functions 状态下过滤数组。这似乎是我应该可以使用 JsonPath 轻松实现的目标,但由于某种原因我正在努力。
我想要处理的状态如下所示:
{
"items": [
{
"id": "A"
},
{
"id": "B"
},
{
"id": "C"
}
]
}
我想通过删除其中的条目来过滤该数组id
不在指定的白名单中。
为此,我定义了一个Pass
表述如下:
"ApplyFilter": {
"Type": "Pass",
"ResultPath": "$.items",
"InputPath": "$.items.[?(@.id in ['A'])]",
"Next": "MapDeployments"
}
这利用了Json路径in操作员 https://github.com/json-path/JsonPath#filter-operators.
不幸的是,当我执行状态机时,我收到一个错误:
{
"error": "States.Runtime",
"cause": "An error occurred while executing the state 'ApplyFilter' (entered at the event id #8). Invalid path '$.items.[?(@.id in ['A'])]' : com.jayway.jsonpath.InvalidPathException: com.jayway.jsonpath.InvalidPathException: Space not allowed in path"
}
但是,我不明白语法有什么不正确。当我测试时here https://jsonpath.herokuapp.com一切正常。
我所做的有什么问题吗?是否有另一种方法可以使用 JsonPath 实现此类过滤器?