CXone Studio SNIPPET: Parsing JSON response from REST proxy

Hi everyone.

I’m working on a Studio flow to check if a contact is a VIP before routing. We need to hit an internal endpoint to get the status. I’ve set up the SNIPPET action with the REST proxy.

The call works fine. I can see the 200 OK in the logs. But when I try to read the JSON response, I’m stuck. The response comes back as a string in the variable rest_response.body.

Here is the snippet code I’m using:

SET rest_response = GETRESTPROXY("vip-check").EXECUTE("GET", "/api/v1/vip/" + contact.phone_number, NULL, NULL, 10000)

IF (rest_response.status == 200) THEN
 // This part is failing
 SET vip_status = rest_response.body.is_vip
 SET contact.vip_flag = vip_status
ELSE
 SET contact.vip_flag = false
END IF

The error in the logs says Cannot read property 'is_vip' of undefined or something similar about parsing. I think rest_response.body is a string and I need to convert it to an object first. I tried using JSON.parse but Studio SNIPPET doesn’t seem to support standard JS functions directly like that.

How do I parse the JSON string into a usable object in Studio? Is there a built-in function or do I need to use a different approach?

Thanks.

Studio doesn’t auto-parse JSON bodies. You’ll need to handle that manually in the snippet.

  • Wrap the body in JSON.parse() immediately after the call.
  • Access properties directly via dot notation on the resulting object.
var data = JSON.parse(rest_response.body);
SET is_vip = data.vip_status;

JSON.parse is the right move, but you’re gonna run into trouble if that endpoint ever decides to send back an error payload or an empty string. Studio snippets don’t throw exceptions the way a standard Node server does, so a bad parse just breaks the variable assignment silently and your flow keeps running with undefined values.

Since I’m usually dealing with state drift in Terraform, I’m paranoid about input validation. You should wrap that parse in a try-catch block. It adds a few lines, but it saves you from debugging weird routing behavior later.

try {
 // Ensure the body exists and isn't empty before parsing
 if (rest_response && rest_response.body) {
 var data = JSON.parse(rest_response.body);
 // Check if the specific property exists to avoid null reference errors
 if (data.hasOwnProperty('vip_status')) {
 SET is_vip = data.vip_status;
 } else {
 SET is_vip = false; // Default fallback
 }
 }
} catch (e) {
 // Log the error to the snippet logs for debugging
 LOG.error("Failed to parse VIP response: " + e.message);
 SET is_vip = false;
}

This way, if the internal API changes its schema or returns a 500 with HTML instead of JSON, your flow handles it gracefully instead of crashing the snippet execution. Always assume the external service is lying to you.