Hi,

My RESTful web service is returning a simple text response with "\n" included within the text. But when the response reach to the end point, an extra back slash is added to all "\n" and became "\\n". Please advise am I doing anything wrong or is this not a correct way of doing thing. 

Response captured using debugger at service studio



Response captured at Postman


From Integration monitor


Thank for viewing.


Regards,

Ye Yint

Hi Ye Yint,

In C and similar-syntax languages, you represent control characters like newline (or line-feed) or tab with an initial '\' followed by some extra character to represent an "escape sequence" (e.g. '\n' for newline and '\t' for tab).

When writing these character literals in a string in those languages you'd use something like:

"First line\nSecond line\n\tThird indented line"

where the compiler would know to interpret the "\n" characters as a change of line, and the "\t" characters as a tab. This means that if you want to actually include the two characters on your string (not the control character) you need to add an extra '\' there... "\\" is how you represent the '\' character in those languages.

From what I see in your screenshots, it seems you are implementing your own REST API method and you're using "\n" in your output string assuming it behaves like in those common languages... when you should be using the NewLine() function to return the newline character instead.

Hope this helps

Hi Jorge,


Thank You for the reply. I tried using "newline()" also but when I use the newline, it produces "\r\n" instead of "\n" only. Is there a way to produce only "\n".


Regards,

Ye Yint

Solution

Hi Ye,

You can use Chr(10) instead of NewLine(). This should produce a \n only.

EDIT: 13 -> 10

Solution

Hi Kilian,


Thank you for the help and reply. I put Chr(10) and it produces exactly as "\n". 

Regards,

Ye Yint

I'm glad it worked :). Happy coding!