I was trying to work with a JavaScript string where a key has a value that is the string representation of an array:
{
"a": "[\"b\",\"c\"]"
}
Interestingly, jsonlint.com states that this is a valid format.
JSON.parse('{"a":"[\"b\",\"c\"]"}');
However, when I try to parse it using JSON.parse(), it throws an error (unexpected token b at position 8). It seems like the issue might have to do with quotes containing escaped quotes - but according to www.json.org, my string should adhere to the standard.
// creating an object with this specific pattern
var o = {};
o['a'] = "[\"b\",\"c\"]";
console.dir(o.a); // -> "[\"b\",\"c\"]"
// examining the JSON string version of this object
var j = JSON.stringify(o);
console.dir(j); // -> {"a":"[\"b\",\"c\"]"}
// attempting to parse a similar string within another variable
var k = '{"a":"[\"b\",\"c\"]"}';
var l = JSON.parse(k); // -> error
So, who is correct in this scenario? Is it jsonlint.com or JSON.parse()?