Why does JSON.parse fail to parse the JSON string below?
Is this not valid JSON?
Strangely, https://jsonlint.com/ validates this string even though its custom JSON parser throws the same error as JSON.parse.
JSON string
{
"Search results: \":s\"": ""
}
Code
let test = `{
"Search results: \":s\"": ""
}`
JSON.parse(test);
Result
VM1882:2 Uncaught SyntaxError: Unexpected token s in JSON at position 22 at JSON.parse () at :1:6
"characters for the outer-level string. You have to double the backslashes because there are two parsing phases.let test = String.raw`{ ... }`String.rawseems to work. do you know why? also would you like to post as an answer?