How to Remove "" from HTTP API JSON Response

Hi All,
From UiPath connecting to a third-party application thorough a HTTP API Call.

Everything works fine, but in the response for one of the tag, the data point contains extra quotation marks (“). Due to this DE Serialize step is failing with exception - Deserialize JSON ResponseContent: After parsing a value an unexpected character was encountered:

See the Comments Tag below

**** JSON RESPONSE CONTENT*****

{“ID”:“56465946434”,“Description”:“testing”,“TktD”:“174819”,“SrcIdentifier”:“178987252499”,“ReferralID”:“”,“Comments”:"This denied.

SOME COMMENTS HEREEEEEEEEEE.”",“Name”:" CARE",“Date”:“19700101T000000.000 GMT”,“code”:“796.00”}

Please suggest how to fix this issue.

Hi @KrishnaKishore

Before deserializing, use an Assign activity to clean the Comments field by replacing extra quotation marks with jsonResponse.Replace(“”“”, “”).
Then, proceed with the Deserialize JSON activity to convert the cleaned response into an object.

If you found helpful, mark as a solution.
happy Automation.

I dont see any extra double quotes in the details provided

Referal id is blank

Are you sure the issue is due to additional double quotes?

Hey @KrishnaKishore
The error occurs because the Comments field in the JSON response contains unescaped double quotes, which breaks the JSON structure.

Try to fix the JSON text in UiPath before deserializing – e.g. with:
cleanJson = ResponseContent.Replace("“", """").Replace("”", """")

or use Regex method:
cleanJson = Regex.Replace(ResponseContent, "(?<!\\)""(?=[^{}\[\]"",:]*"")", "'")

Hi Team,
We tried the same, but instead of replacing the extra ones, its replacing in the entire JSON text and still the deserialize step fails.

Is some thing i need to change in the HTTP activity configuration parameters. Also in some scenarios i may get the ", { } : () ’ " characters.

So please help to deserialize the response in better way.

@KrishnaKishore
If the issue only affects the Comments field, you can use Regex to extract it, clean it, and replace it in the JSON string:
BlankProcess9.zip (33.5 KB)

pattern = "Comments"":\s*""((.|\n)*?)"""

matches = System.Text.RegularExpressions.Regex.Matches(originalJson, pattern, RegexOptions.Singleline)

cleanComments = System.Text.RegularExpressions.Regex.Replace(matches(0).Groups(1).Value, "[\u201C\u201D]", "")

cleanedJson = System.Text.RegularExpressions.Regex.Replace(originalJson, pattern, """Comments"": """ & cleanComments & """")

This way you can avoid deserialization errors while keeping the rest of the JSON intact

Thanks @pikorpa Let me try this options. But couple of questions:

  • I’l receive multiple nodes as JSON Array. In that case how we can filter these extra quotation marks from each of these array Comments Field.
  • In Some scenarios, i’ll recieve empty Comments value too: ex: “Comments”: “”
  • In your example, quotation marks is different than what i am seeing in my JSON Response

@KrishnaKishore
If you’re receiving multiple items as a JSON array, you can loop through each item and check the Comments field individually.
If the Comments field is empty (""), you don’t need to do anything - just make sure you check for null or empty string before applying replacements.
Regarding the quotation marks - if yours are different you can make sure to copy and paste them directly from your JSON into the .Replace statement for accurate matching.

Sorry, my question was, Without deserialize the json response which is string, how can i loop all these array elements?

Hey @KrishnaKishore
Please try this flow:
BlankProcess9 (2).zip (36.9 KB)

Sorry to ask this, the comments value is multi line and having JSON Character like {} , : ..etc

How to handle these multiline and chars ? I tried the same matched pattern and its not taking the text/replacing in the second line.

Please help.

@KrishnaKishore
This flow should be able to handle multi-line comments and special characters.
If it still doesn’t work, feel free to share a larger portion of the original JSON response, so I can check it out.

Response: [{“ID”:“56465946434”,“Description”:“testing”,“TktD”:“174819”,“SrcIdentifier”:“178987252499”,“ReferralID”:“”,“Comments”:"My Comment.

“First Line Break.”",“Name”:" CARE",“Date”:“19700101T000000.000 GMT”,“code”:“796.00”}, {“ID”:“56465946434”,“Description”:“testing”,“TktD”:“174819”,“SrcIdentifier”:“178987252499”,“ReferralID”:“”,“Comments”:“My Comment.“WithoutLine breakCRLF.”",“Name”:” CARE",“Date”:“19700101T000000.000 GMT”,“code”:“796.00”}, {“ID”:“56465946434”,“Description”:“testing”,“TktD”:“174819”,“SrcIdentifier”:“178987252499”,“ReferralID”:“”,“Comments”:“",“Name”:” CARE",“Date”:“19700101T000000.000 GMT”,“code”:“796.00”}, {“ID”:“56465946434”,“Description”:“testing”,“TktD”:“174819”,“SrcIdentifier”:“178987252499”,“ReferralID”:“”,“Comments”:"My Comment.

“Another Line Break.”",“Name”:" CARE",“Date”:“19700101T000000.000 GMT”,“code”:“796.00”}, {“ID”:“56465946434”,“Description”:“testing”,“TktD”:“174819”,“SrcIdentifier”:“178987252499”,“ReferralID”:“”,“Comments”:"Special Chars.

“Third Line Break..: (12233,4545}.”",“Name”:" CARE",“Date”:“19700101T000000.000 GMT”,“code”:“796.00”}], “ResultsCount”: 4}

@KrishnaKishore
Hey, to be honest - the JSON looks broken and can’t really be parsed properly without cleaning and fixing it globally. It’s not just one field - the whole structure needs to be adjusted.
Once I have a bit of time, I’ll try to take a look and come up with something that could automatically repair it. Will keep you posted!

By the way - would it be possible to ask the data provider to adjust the JSON format so that it complies with proper syntax?

InvalidFormat_JSON.txt (4.1 KB)
ValidFormat_JSON.txt (4.1 KB)

hi @pikorpa Attached the my JSON format. I think under comments field, extra CRLF is causing the JSON to break. So we need to replace these CRLF chars under the “Comments” Filed so that JSON looks good and deserialize happens without exceptions. Can you please help me to frame the regex to clean/scrub these fields from JSON Text.

It doesnt make sense to be that the JSON response doesn’t have the quotation marks escaped. It seems like an invalid response to be honest.

Can you try running it through Postman and seeing if that also rejects it or the quotation marks are escaped? If its also invalid in Postman then this is for sure a bug with the API and they are building their ‘JSON’ in a hacky way and doing it wrong and you should contact the third party vendor to report a bug.

Hey @KrishnaKishore

Attached is the working project that processes the JSON successfully - it extracts all the Comments fields, cleans them from invalid line breaks or characters, and allows proper deserialization without errors.
BlankProcess9 (3).zip (122.8 KB)

That said, it’s worth pointing out that the original input you’re receiving is technically not a valid JSON.
Ideally, this should be handled on the sender’s side - the system generating the JSON response should ensure that all string content is properly escaped so it conforms to JSON standards.

Still, I implemented a workaround in UiPath to clean up the Comments field before deserialization, and it works as expected now :slight_smile:

2 Likes

@pikorpa Thanks, this worked. And worked with source system to scrub the data before sending the response.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.