CXone Studio GetRESTProxy: JSON parsing fails when response contains nested arrays

We are trying to fetch dynamic configuration data from an internal API within a CXone Studio script. The goal is to retrieve a list of priority codes and map them to specific queue names based on the caller’s input.

The HTTP call itself works. I can see the 200 OK status in the trace logs. However, when I attempt to parse the JSON response body into a Studio variable using the standard dot notation, the variable ends up empty or throws a type mismatch error downstream.

Here is the snippet configuration:

Action: GetRESTProxy
Method: GET
URL: https://api.internal.company.com/v1/priorities
Headers: Content-Type: application/json
Response Variable: apiResponse

The response payload looks like this:

{
“status”: “success”,
“data”: [
{
“code”: “P1”,
“queue”: “urgent_support”
},
{
“code”: “P2”,
“queue”: “standard_support”
}
]
}

I am trying to assign the first queue name to a variable called targetQueue using this expression in a subsequent ASSIGN action:

apiResponse.data[0].queue

Studio is rejecting this syntax. It seems like the GetRESTProxy action returns the body as a raw string, and Studio’s internal JSON parser is struggling with the array index [0]. I’ve tried wrapping it in json_decode functions available in other platforms, but those aren’t available in CXone Studio snippets.

Is there a supported way to iterate over or index into a JSON array returned by a REST proxy action? Or do I need to flatten the response structure on the API side before sending it? The current approach feels fragile, and we’ve been stuck on this for two days.

Studio’s JSON parser is notoriously strict about nested structures. If your API returns an array of objects, Studio doesn’t always flatten it automatically into a simple list you can iterate over with a standard “For Each” loop. You often have to manually extract the elements.

Check your response structure. If it looks like {"items": [{"id": 1}, {"id": 2}]}, you can’t just reference response.items. You need to parse it step-by-step.

Try this flow:

  1. GetRESTProxy: Set the response body to a variable, say rawJson.
  2. JSONParse: Use the action to parse rawJson. Set the output to parsedData.
  3. Extract Array: If the root is an object, you might need another action or a script block to isolate the array key.

Here is a safer way to handle it using a script block if the built-in actions fail:

// Studio Script Block
var raw = session.getVariable("rawJson");
var data = JSON.parse(raw);

// Check if the response is an array or an object containing an array
if (Array.isArray(data)) {
 session.setVariable("priorityList", data);
} else if (data.items && Array.isArray(data.items)) {
 session.setVariable("priorityList", data.items);
} else {
 session.setVariable("parseError", "Unexpected JSON structure");
}

Make sure your priorityList variable is defined as a List<Object> or List<String> depending on what you need downstream. If you define it as a simple string, it will break.

Also, verify the content-type header in your REST call. Sometimes the API returns text/plain even with JSON content, which tricks Studio into treating it as raw text rather than a parseable object. Force application/json in the headers if possible.

This approach avoids the type mismatch because you’re explicitly controlling the parsing logic instead of relying on Studio’s implicit conversion. It’s a bit more verbose, but it’s reliable for WEM integrations where data consistency matters.