Susmit Sarkar
Susmit Sarkar

Reputation: 57

Media Type application JSON type response for new line characters getting replace by \n

We have a JSON string:

enter image description here

We are reading this data from a file:

enter image description here

We are sending this object as a response, which is finally returned as a JSON response.

When we get the response finally we are having \n

-----BEGIN PGP PRIVATE KEY BLOCK-----\nVersion: BCPG v1.68\n\nlQIGBGEWHLIBBACpxENhYQYOtg2iSesz0PsfygEX2ISdLV0mSsDm4Ssf0vlPva9p\nPzmbB4IQwbkD+DhAyWvt2rkjjpfAwfz/NGpBwOsen/EX9Y15rhy4yezskF8Cy81m\nB3w0PmsYzA0AYFEKsEvAJlRoEYVtmDhPIe3s1T/1JtJz8L5wYdnEw2mbPQARAQAB\n/gkDCG/j9FQsQFSkwNcklFVHLzimvc6xbxGdYOmquGqr7jeRfooGH9HmFYBWuyQe\nkW8Klu1AqqFI/dx0q+nH5B+b+cg3FtZu4/3IUfHIgo4iVwepq7+rjR56ofAuZ+6B\n5m01XFLtiidNSLqqKWoX07zq8C4yUWWxyxDb1adp/8qgcCem4+hLCedmQMk21Bip\nafbonkwyGTcVh4nY1LlVv80Aewzoe6XljC9hu+Wh7L3riX0GUZptx4grqJQ8I0AJ\nDV1cN/Z572m6OvzfQxXei7jmvD3jyy6enDV3lTllUq65fbPOaHmmaH5v0Lgt0BrK\nUmgwjRbTxL5vee9zvBEvkg6RnZkECte+SHlCuojbFuTDTinuWTu5jyt8sGoZjzzf\nh4n3GTjzlcaqE4ivzHs3raQkxgOm8ka4zrl1snGBgnlUg5wrJXsV+7kpWQaC9FnI\nrwmsvbGBiFpWLn9A4uHo4Uw3Y5jiff9AdMBG1mfPW/1uk16nKY0NhoS0CmprZHNo\nZmtzZGqIpQQQAQoADwUCYRYcsgIbLwUJAIPWAAAKCRAUwv03KA6laP4nA/9c4j0d\noI2OP/6nzE09PKI8GVxWlWD+G9uDv8xBDbprQBnfomKGXuBtQIY7Ar+Nh4WlvpUH\nNmd5RaE5kyeSIqdTTdJvFDeupbrvObDyvbp6vHLzP1NlWFieIm53Dx9YyCH/4cLt\nUEpEw5SDnbEO/tyX5AxaycJ6uMRqFBl5tT8JWw==\n=t3Hn\n-----END PGP PRIVATE KEY BLOCK-----\n"

What will be the ideal way to solve this issue, as I have no control to replace the \n new line character with empty strings followed by a new line.

Thanks.

Upvotes: 0

Views: 398

Answers (1)

Ashutosh Mishra
Ashutosh Mishra

Reputation: 89

Since string identifies \n as new line you can't do anything to stop it as you are reading from file and storing it to string object. It can't be avoided but can be handled at client side or whosoever use your api can handle at their code level. Hopefully this clarifies.

Upvotes: 1

Related Questions