Loop block index out of bounds when iterating Data Action JSON array

Anyone know why the Loop block in Architect throws a RuntimeError: Index 5 is out of bounds for array length 5 when iterating over a JSON array returned from a custom Data Action? The Data Action returns a valid JSON array of 5 objects via /api/v2/data-actions/custom/my-action, but the loop fails on the final iteration despite the count matching.

["id": "1", "val": "A"],
["id": "2", "val": "B"],
["id": "3", "val": "C"],
["id": "4", "val": "D"],
["id": "5", "val": "E"]

The Loop block is configured to iterate over {{data.action.response.body}}. According to Genesys Docs, the loop should handle the full array length. I have verified the JSON path is correct and the payload is not null. Is there a specific indexing quirk with the Loop block or the Data Action response structure?

According to the docs, they say that Architect Loop blocks expect a standard JSON array format, but the error message Index 5 is out of bounds for array length 5 often points to a parsing issue rather than a true index error.

I hit this exact 401-style logic error when my Data Action returned malformed JSON. Look closely at your sample data: ["id": "1", ...]. Those square brackets [] around key-value pairs create an invalid JSON structure. Standard JSON objects use curly braces {}. If the parser fails on the first element, the resulting array might be empty or contain nulls, causing the loop to crash when it tries to access index 5 on a broken structure.

Ensure your Data Action returns valid JSON like this:

[
 {"id": "1", "val": "A"},
 {"id": "2", "val": "B"},
 {"id": "3", "val": "C"},
 {"id": "4", "val": "D"},
 {"id": "5", "val": "E"}
]

Also, verify the content type header in your custom Data Action is set to application/json. If it defaults to text/plain, Architect might treat the response as a string instead of an array, leading to unexpected length calculations.

Since I am still debugging token refresh issues in my Python scripts, I tend to over-validate responses. Here is a quick curl test you can run to validate the payload before it hits Architect:

curl -X POST https://api.mypurecloud.com/api/v2/data-actions/custom/my-action \
 -H "Authorization: Bearer {{your_token}}" \
 -H "Content-Type: application/json" \
 -d '{}' | jq .

If jq throws a parse error, your Data Action logic is the culprit. Fix the JSON syntax to use curly braces for objects, and the Loop block should iterate through all 5 items without throwing an out-of-bounds error.

This issue stems from the Data Action returning a structure that Architect cannot parse as a standard iterable array, even if it looks like one in the raw output. I ran into this exact issue when transitioning from Five9, where the platform was more forgiving with loosely typed responses. CXone Studio expects strict JSON arrays of objects, not arrays of malformed key-value pairs or mixed types.

RuntimeError: Index 5 is out of bounds for array length 5

The error message is misleading. It’s not actually an index-out-of-bounds error in the traditional sense. It happens because the Loop block tries to access index 5 (the 6th item) after successfully iterating through indices 0-4, but the underlying data structure isn’t recognized as a contiguous array by the runtime engine. This often occurs when the Data Action’s success output contains a JSON string that hasn’t been properly parsed into an object/array type, or when the JSON itself is invalid.

In your sample, you showed ["id": "1", "val": "A"]. That’s invalid JSON. It should be [{"id": "1", "val": "A"}]. If your Data Action is returning a string representation of JSON, you need to parse it first. Add a Studio Snippet before the Loop block with this code:

var rawJson = GetRESTProxy().body; // or your Data Action output variable
var parsedArray = JSON.parse(rawJson);
return { array: parsedArray };

Then, configure the Loop block to iterate over the array variable returned by the snippet. Also, double-check that your Data Action’s success response schema in the NICE CXone portal matches the actual JSON structure. If the schema expects an object but you’re returning an array, the runtime might cast it unexpectedly. I always validate the response in Postman first using the exact same OAuth token scope (data-actions:read or data-actions:write depending on your action) to ensure the payload is clean before wiring it into Architect.