Looking for advice on iterating over a JSON array returned from a Data Action using the Loop block in Genesys Cloud Architect. I am building a flow that fetches user permissions via a POST request to our internal API, but the Loop block seems to ignore the array elements, processing only the first item or failing entirely.
The Data Action returns the following JSON payload:
{
"statusCode": 200,
"body": {
"permissions": ["read", "write", "delete"]
}
}
I have mapped the output to a string variable $.data.permissions. My steps to reproduce are:
- Create a Data Action with method POST and URL
https://api.internal/get-perms.
- Map the response
body.permissions to $.data.permissions.
- Add a Loop block after the Data Action.
- Set the Loop source to
$.data.permissions.
- Set the loop variable to
$.loop.currentItem.
- Add a Set Variable block inside the loop to assign
$.loop.currentItem to $.currentPermission.
- Add a Log block to output
$.currentPermission.
The log only shows the string “[read, write, delete]” instead of individual items. The Loop block expects an array structure, but the Data Action output is a string. How do I correctly convert or reference the array in the Loop configuration? I have tried using JSON.parse in an Expression block, but the syntax is unclear for Architect.
This looks like a missing unwrap step. The Loop block requires a flat array, so you must add a JSON Parse block before it to extract the inner list using the expression $.body.permissions.
The main issue here is that the Loop block in Architect expects a strict JSON Array type, but the Data Action returns a complex object containing the array. While the JSON Parse suggestion above is on the right track, you are likely hitting a type mismatch because the parse output is still an object. You need to explicitly extract the array property before feeding it into the loop. In the TypeScript SDK, this is handled by model definitions, but in Architect, you must use the Data Action’s output mapping or a subsequent Data Action to isolate $.body.permissions. Ensure the Data Action returning the API response is configured to return the body as a string, then use a JSON Parse Data Action with the input set to $.previousStep.output.body and the expression $.permissions. This outputs a pure array. Connect this output to the Loop block’s “Input List”. If the loop still fails, verify that the items in the array are not null; Architect loops skip null entries silently. For a robust pattern, wrap the loop in a Try/Catch block to handle malformed JSON from your internal API. See the architectural best practices guide for data transformation patterns here: https://developer.genesys.cloud/articles/architect-data-transformation-patterns. This ensures your flow remains stable even if the upstream API changes its response structure. The key is maintaining type purity between blocks.