Reputation: 691
When I have this input
{
"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"
}
and using MapIterator with following line:
"Items": "{% $states.input.object_keys[Size>0].Key %}"
I get an error:
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\"
If I add one more key with size greater then 0, then I get array of two items and everything is fine. Why I do not get ["aws/lambda/5e7faac5-052a-4ac2-a032-2c1ad3a28459/shardId-000000000002/2024/11/29/2024-11-29T15.57.25-16468255-9704-44d9-93b6-c2c256daa914"] instead list is transformed to string? It looks like a bug.
Upvotes: 1
Views: 238
Reputation: 131
To make the JSONata expression always return an array, you need to add square brackets somewhere in the path, like so:
"Items": "{% $states.input.object_keys[Size>0].Key[] %}"
Link to JSONata playground: https://jsonatastudio.com/playground/f789749e
Upvotes: 0