This is not an error, it is due to the way the string literal is processed in JavaScript. When you have:
'{ "hello": "hi\nlittle boy?" }'
... your string will be parsed for:
{ "hello": "hi little boy?" }
... before it is passed to parseJSON() . And this is clearly not JSON, since \n was converted to a newline letter in the middle of "hello little boy"? line.
You want the sequence " \n " to jump to the parseJSON() function before converting to a literal newline. For this to happen, it must be double-escaped in a literal string. How:
'{ "hello": "hi\\nlittle boy?" }'
Example: http://jsfiddle.net/m8t89/2/
source share