4

We are using a WCM tool for content entry and content editors will enter content having text and html in the tool. To convert the content into JSON we are using newton JSON as below where we are passing simple dictionary of keys and values:

string output = JsonConvert.SerializeObject(nonJsonResult);

Whenever editor gives content with new lines then we are getting the serailized JSON output with \r\n.

Example input text:

first line

second line

third line

Output:

 {
     "test": "first line\r\nsecond line\r\nthird line"
 }

Is there a way to avoid these characters? If it is inevitable, will these \r\n pose an issue for the other application to which we are sending the JSON response? Are there any more issues like these with newton JSON as I am fairly new to JSON which I need to take care of.

Mahdi
  • 3,199
  • 2
  • 25
  • 35
Guestuser1122
  • 403
  • 1
  • 4
  • 10
  • I don't think these are new lines, I found them to be spaces [here](http://jsonviewer.stack.hu/) – Amit Kumar Ghosh Jan 12 '17 at 07:52
  • 4
    `\r` (carriage return) and `\n` (newline) are standard escape sequences explicitly specified in the [JSON standard](http://www.json.org/). Any system that reads JSON should recognize these escape sequences as a new line sequence. – dbc Jan 12 '17 at 09:04
  • 1
    You get out what you put in. If you put in strings with newlines, they will be in the JSON as some combination of \r and \n depending on the system, and when the other end parses the JSON it should result in strings with those newlines again. – RemcoGerlich Jan 12 '17 at 11:51

0 Answers0