当我有这个输入时
{
"input": {
"bucket_name": "ml-platform-qa-us-east-1",
"object_keys": [
{
"Key": "aws/lambda/5e7faac5-052a-4ac2-a032-2c1ad3a28459/shardId-000000000002/2024/11/29/",
"Size": 0
},
{
"Key": "aws/lambda/5e7faac5-052a-4ac2-a032-2c1ad3a28459/shardId-000000000002/2024/11/29/2024-11-29T15.57.25-16468255-9704-44d9-93b6-c2c256daa914",
"Size": 178665
}
]
},
"inputDetails": {
"truncated": false
},
"name": "Map: Iterate over failed events"
}
并使用 MapIterator 和以下行:
"Items": "{% $states.input.object_keys[Size>0].Key %}"
我收到错误:
An error occurred while executing the state 'Map: Iterate over failed events' (entered at the event id #14). The JSONata expression '$states.input.object_keys[Size>0].Key' specified for the field 'Items' returned an unexpected result type. Expected 'array', but was 'string' for value: \"aws/lambda/5e7faac5-052a-4ac2-a032-2c1ad3a28459/shardId-000000000002/2024/11/29/2024-11-29T15.57.25-16468255-9704-44d9-93b6-c2c256daa914\"
如果我再添加一个大小大于 0 的键,那么我会得到两个项目的数组,一切都很好。为什么我没有得到[“aws/lambda/5e7faac5-052a-4ac2-a032-2c1ad3a28459/shardId-000000000002 /2024/11/29/2024-11-29T15.57.25-16468255-9704-44d9-93b6-c2c256daa914"]相反列表被转换为字符串?看起来像一个错误。
要使 JSONata 表达式始终返回数组,您需要在路径中的某处添加方括号,如下所示:
"Items": "{% $states.input.object_keys[Size>0].Key[] %}"
JSONata 游乐场链接:https://jsonatastudio.com/playground/f789749e