https://jsbin.com/zuhatujoqo/1/edit?js,console
Edit: json file has this line:
{"pd":"ciao \\n ste"}
I need to retrieve a valid JSON file through an ajax call.
Then parse the result using JSON.parse.
I'm confused about the behavior of the "\\n" escape character found in my JSON file.
When I use JSON.parse with the same values, it gives me different results.
var result = JSON.parse(data);
console.log(result);
var result2 = JSON.parse('{"pd":"ciao \\n ste"}');
console.log(result2);
My understanding is that JavaScript might be escaping (or unescaping?) the string before parsing it.
The issue arises when I try to do this:
result = result.replace(/\\n/g, "<br />");
Do I also need to escape the regex itself?
In summary: I want to load the .json file via Ajax. I expect JSON.parse to properly handle the "\\n" by converting it into a NewLine character.