Support Article
REST not returning correct JSON response, Unexpected token
SA-12685
Summary
When a REST Service is called and returns a property value that has a double quotation mark (") in it, it treats the quotation mark character as the end of the JSON string and returns an error. For example, if you retrieve the string {"Name":"Aabbccddee1234567890!"£$%^&*()<,>.?/:;@'"} after the double quotation mark ("), the JSON is no longer valid.
It sees the double quotes as enclosing the double quotes at the start of the value "Aabbccddee…, and it now expects a , } or { character.
It appears that the string has not been properly encoded, meaning that the JSON is malformed.
If you set the property ServiceResponseOne in your example below to Aabbccddee1234567890!"£$%^&*()<,>.?/:;@'" then, when you call the service externally, it will trigger an error.
Error Messages
“Unexpected token £”
Steps to Reproduce
Create a REST Service and retrieve a property value that includes double quotation marks (") and other characters after it.
Root Cause
JSON response generated from PRPC REST Service is not adhering to JSON specification. This is happening when a property value contains some characters that are must be escaped as specified in RFC7159. Not all the special symbols causes invalid JSON. The symbols that causes invalid JSON are ", \, /, backspace, formfeed, newline, carriage return, horizontal tab, hexadecimal digits.
For Pega 7.1.5, the Pega 7 Platform does not handle these special symbols when outbound mapping JSON text.
As a workaround, escape the outbound JSON text to arrive at a valid JSON. Since it adds to performance overhead, as each and every character is to be checked, add a DSS to escape the JSON conditionally.
This behavior is effective with a Dynamic System Setting (DSS) specified as follows:
Purpose : json/escapeSpecialCharacters
Owning Ruleset : Pega-IntSvcs
Value : true
Resolution
Apply HFix-23009.for Pega 7.1.5.
Best practice: Upgrade to the latest Pega 7 Platform release.
If you cannot upgrade and you are using Pega 7.1.6, apply Hfix-25280.
The issue described here was fixed in Pega 7.1.9.
On the PDN Resolved Issues page,specify ISSUE 208239 and Pega 7.1.9 to see the results
On the search results page, click the release note Title to open the release note:
Added escaping for JSON special characters in REST
Published February 2, 2017 - Updated October 8, 2020
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.