What is the reason behind being unable to parse a json with a \n
character in javascript?
JSON.parse('{"x": "\n"}')
Surprisingly, when you use
JSON.parse(JSON.stringify({"x" : "\n"}))
, it works perfectly fine.
indicates that {"x": "\n"}
is valid JSON. The mystery remains about what the official spec has to say about this.
Update: To those who consider this duplicate, it should be noted that this question delves into why an unescaped newline character is not allowed in JSON rather than discussing how to handle newlines in JSON.