JSON encoding - String contains control character

Not applicable

Morning All,

I'm working on an integration and for some reason am having issues with JSON encoding:

I have to JSON encode the description, short description and work notes when sent. I'm getting a catch error of String contains control character. Below is the description that's tripping it up and the payload being sent, any suggestions are appreciated:

Description:

This is a test description Please ignore this WO request

&
"
'
< 
>

 

Payload (some data redacted):

{
    "Header": {
        "TransactionID": "INC2072276-2021-09-16 09:22:14",
        "USERID": "#####",
        "SourceSystem": "#####",
        "TimeStamp": "2021-09-16T09:22:14"
    },
    "CreateServiceRequest": {
        "CountryCode": "US",
        "ServiceRequest": {
            "CustomerTicketID": "INC2072276_0",
            "Type": "MAIN",
            "Priority": "3",
            "Summary": "&quot;Test of incident creation 2021-09-16 NEW with Special Characters&quot;",
            "Description": "&quot;This is a test description Please ignore this WO request\r\n\r\n&amp;\r\n\&quot;\r\n&apos;\r\n&lt; \r\n&gt;&quot;",
            "Caller": {
                "FirstName": "Trevor",
                "LastName": "Brown",
                "PhoneNumber": {
                    "Country": "001",
                    "AreaCode": "###",
                    "PhoneNumber": "####"
                }
            },
            "Site": {
                "SiteShortName": "01805"
            },
            "CI": {
                "SerialNumber": "####"
            },
            "ATMCustomerMetrics": {
                "SSDGCustomer": "false"
            },
            "NCRMCN": "####",
            "Remarks": {
                "Remark": [{
                    "Text": "&quot;2021-09-16 09:22:07 - Simon E Hayward (Work notes)\nCreated from a similar incident INC2072274\n\n&quot;",
                    "Type": "General"
                }]
            },
            "attribute3": "#####"
        }
    }
}

 

1 ACCEPTED SOLUTION

Not applicable

try with JSUtil.escapeText(String) and then serialize

View solution in original post

3 REPLIES 3

Not applicable

try with JSUtil.escapeText(String) and then serialize

Not applicable

Thank you, swapped the encode with this and now it works perfectly.

Not applicable

Great! 

🙂