You can definitely use string methods in the response template.
https://help.mypurecloud.com/articles/velocity-macros-data-actions/#JavaStringMethods
Original Message:
Sent: 04-29-2025 02:28
From: Konstantinos Pappas
Subject: Usage of $esc.jsonDecode()
Hello Jason,
It seems that there is no substring or similar function to use in the response configuration.
The issue is the additional backslashes that are inserted during the resolve translation map and make the $esc.jsonDecode() inva;id.

------------------------------
Konstantinos Pappas
Contact Center Solution Engineer
Barphone SA
Original Message:
Sent: 04-28-2025 15:21
From: Jason Mathison
Subject: Usage of $esc.jsonDecode()
Is the issue that you are ending up with an extra set of quotes around the JSON object? If so, you should be able to remove the first and last character from $contactInfo, so something like
$contactInfo.substring(1, $contactInfo.length() -1)
------------------------------
--Jason
Original Message:
Sent: 04-25-2025 06:55
From: Konstantinos Pappas
Subject: Usage of $esc.jsonDecode()
I need to save the transformed string to JSON to an object variable declared in Contracts and then save the values of the fields of the output to string variables in the script.
Let's say i have this string: "{\"id\":\"XXXX\",\"kunnr\":\"1111111\",\"cid\":\"111YYY\",\"groupId\":\"001\"}".
I need to transform it into JSON through the response config:
{
"id":"XXXX",
"kunnr":"1111111",
"cid":"111YYY",
"groupId":"001"
}
Which is going to be saved in an object variable named contactInfo.
In this way, I can retrieve every field to the script in this way: kunnr = contactInfo.kunnr etc.
------------------------------
Konstantinos Pappas
Contact Center Solution Engineer
Barphone SA
Original Message:
Sent: 04-25-2025 06:46
From: Jan Heinonen
Subject: Usage of $esc.jsonDecode()
So what will you do with the object in Script?
There's no JSON type variable so it might not matter if the object is returned as a string.
------------------------------
Jan Heinonen
Contact Center Specialist
GlobalConnect AB
Original Message:
Sent: 04-25-2025 06:37
From: Konstantinos Pappas
Subject: Usage of $esc.jsonDecode()
According to this article: https://help.mypurecloud.com/articles/velocity-macros-data-actions/
esc.jsonDecode
When you have a JSON encoded string and want to have JSON form of it, you can use the esc.jsonDecode() macro. This macro unescapes quotes and other characters based on JSON encoding rules.
Template example
$esc.jsonDecode(${input.escapedjson})Decoding example
| Input | Output |
|---|
{\n\t\"foo\":\"bar\"\n} | { "foo":"bar" } |
I see your approach, however the data action in going to be used in script, so the output cannot be manipulated as in Architect.
------------------------------
Konstantinos Pappas
NA
Original Message:
Sent: 04-25-2025 06:30
From: Jan Heinonen
Subject: Usage of $esc.jsonDecode()
The jsonDecode as I understand only remove escape characters of a string.
I don't think you can return an object, you can return it as a string, and then parse it into JSON in for example Architect if that's where you're using it.
For objects with nested arrays I often just return the rawResult as a string and then JSON.parse that in Architect.
------------------------------
Jan Heinonen
Contact Center Specialist
GlobalConnect AB
Original Message:
Sent: 04-25-2025 03:10
From: Konstantinos Pappas
Subject: Usage of $esc.jsonDecode()
Hello all,
I face a problem using $esc.jsonDecode(). I am trying to get a field that is filled with JSON in string form and transform it to JSON object, in order to get some specific fields from it. To be more specific, I save the JSON in string form in the field $.entities[X].customFields.example_field and I retrieve it in translation map to a variable. Then, in successTemplate I try to transform it to JSON to save it to a variable that is declared as object in Contracts. Example response configuration:
{
"translationMap": {
"contactInfo": "$.entities[0].customFields.contactInfo_longtext"
},
"translationMapDefaults": {},
"successTemplate": "{\n \"kunnr\": $esc.jsonDecode($contactInfo) \n}"
}
I tried many different approaches, observing that in translation map, I can only save the data to string variable.
If anyone has used the function $esc,jsonDecode in a similar situation. feel free to share your response configuration.
BR,
Konstantinos Pappas
#DataActions
------------------------------
Konstantinos Pappas
NA
------------------------------