Converting IS document to JSON string for special characters

Product/components used and version/fix level: webMethods IS

Detailed explanation of the problem:

Issue while converting IS document to JSON String.

Details:
If there is any special character like \ (Example Input: Request to perform test\trial ) in any of the field of IS document. After converting to JSON string by using documentToJsonString built in service, one extra \ is coming in output. (Example Output: Request to perform test\\trial ).

Please let me know if it is expected behavior of built in service, if ‘yes’, is there any way to avoid sending double special characters to source system.

Thanks,
Sourab

Error messages / full error message screenshot / log file:

Question related to a free trial, or to a production (customer) instance?

Yes, this is required behavior. JSON defines JSON syntax.

If a literal \ is included in the data, it must be escaped. If it is not escaped, the JSON will not be valid. The “source system” must be able to accept escaped data if it supports JSON.

[Edit]: The only characters that must be escaped in string values are \, ", and control codes (anything less than U+0020). Other markup characters used in JSON do not need to be escaped in string values. But in any case, the built-in service that creates the JSON string does the right thing – so we don’t need to worry about it. :slight_smile:

As an example, consider the following IS document containing a single field named “foo” and the value “Same rule applies to every character({ } [ ] \ " ' : )”

Note that in the resulting jsonString that \ and " are escaped, as expected/required.

\ is the escape character for json strings. If you need to use the escape character as a character, you need to escape it. Same rule applies to every character({ } [ ] \ " ' : ) that is defined in JSON syntax. All these chars have a specific purpose in the JSON syntax. There is no way parser can distinguish these with the chars in string, unless you escape them.

Dear Reamon, Engin SARLAK,

Thanks a lot for sharing the information on this topic.:slight_smile:

Thanks,
Sourab M V