JSON text is not a subset of PrimaryExpression
mikesamuel at gmail.com
Tue Jul 11 13:33:28 UTC 2017
Valid JSON text is a subset of the ECMAScript PrimaryExpression syntax
as modified by Step 4 above. Step 2 verifies that JText conforms to
that subset, and step 6 verifies that that parsing and evaluation
returns a value of an appropriate type.
IIUC, if JSON text where a subset of PrimaryExpression then there
should be no string that parses via JSON.parse which does not eval
when wrapped in parentheses.
On recent (Chrome, Safari, Firefox),
var s = String.fromCharCode(0x22, 0x2028, 0x22)
JSON.parse(s); // Passes
eval('(' + s + ')'); // raises SyntaxError
I believe the only reason it's not a subset is that both exclude line
terminators from quoted string bodies but JSON does not treat U+2028
and U+2029 as line terminator chars while EcmaScript does.
Could we change "is a subset of" to "is almost a subset of" or "is a
subset (modulo LineTerminators) of"?
Some related discussion at
More information about the es-discuss