CXone Studio GetRESTProxy JSON parse error

I’m trying to parse a JSON response from an internal API in a CXone Studio snippet. The call works fine, but the ASSIGN action fails every time.

SET result = GetRESTProxy("https://internal/api/data", "GET", "", "")
SET json = result.json

It throws Invalid JSON. The response looks valid in debug mode. What am I missing?

That result.json syntax is the blem. In CXone Studio, GetRESTProxy doesn’t return a parsed JSON object directly. It returns a raw string in the body perty. You’re trying to access a perty on a string, which either returns null or triggers a type error depending on how the engine interprets it.

You need to explicitly parse the string. Studio has a built-in JSON.parse function for this. Here’s how you should structure those assignments:

// 1. Make the call and capture the full response object
SET response = GetRESTProxy("https://internal/api/data", "GET", "", "")

// 2. Check the status code first. It's a bad habit to parse on 4xx/5xx errors.
IF response.status >= 200 AND response.status < 300

 // 3. Parse the body string into a usable object
 SET jsonData = JSON.parse(response.body)

 // 4. Now you can access fields safely
 SET userId = jsonData.id
 SET userName = jsonData.name
 
ELSE
 SET error = "API call failed with status " + response.status
END IF

Also, watch out for encoding issues. If your internal API returns UTF-8 with BOM (Byte Order Mark), JSON.parse will choke on the hidden characters at the start. You might need to strip the BOM first if that happens.

One other thing: if the payload is large, JSON.parse can sometimes timeout or hit memory limits in Studio. If you’re only needing one field, consider using a regex or string manipulation to extract it, though that’s messier. For most cases, the parse method above works fine.

I ran into this last week with a similar setup. The debug log showed the JSON looking perfect, but the variable assignment was silently failing because it wasn’t actually an object yet. Once I switched to JSON.parse(response.body), it clicked into place.

Check your response.body in the debugger before parsing. If it’s empty, your GetRESTProxy call might be failing silently earlier in the flow.