Json variable to keep new line breaks

Hello all,

I have been working on a solution that takes in customer comments from a form and uploads them into another system. Both use Rest APIs with json. Everything works fine until I came across an entry with multiple new line returns in it. I am reading this in as a string and uploading to the another system. This works when there is only 1 line. However, if it breaks it into multiple line the upload API fails due to the formatting.

My question is, is there a specific variable type I can store the initial API comments as? Or, is there a way to look for the new line returns and add them back into the API that posts into the other system. Saving the response as a string removes the \r\n as I would expect. Any suggestions are greatly appreciated.

Example response: “Hello, \r\n Thank you for contacting me on the process. \r\n\r\n It was great working with you.”

Did you try this:
processedString = originalString.Replace(vbCrLf, “\r\n”).Replace(vbCr, “\r”).Replace(vbLf, “\n”)

This replaces Windows (vbCrLf ), Mac (vbCr ), and Linux (vbLf ) newlines with their escaped versions.


we recommend to clear check that the expectation of serialized / not serialized json string is met.
Along with \n\r maybe other like \" \\ is to touch as well

1 Like

Thank you @pikorpa,

That works perfectly. Thanks for the quick response.

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