Re:Unintuitive JSON Parsing
by spankalee on Saturday December 28, 2019 @02:55PM
(#21901303)
The article leads with an incorrect statement. JSON is now a subset of JavaScript: https://github.com/tc39/proposal-json-superset
[ Parent
| on HN ]
Re:Unintuitive JSON Parsing
by wereHamster on Saturday December 28, 2019 @03:26PM
(#21901495)
According to the proposal, this has been shipped in V8 in Chrome 66 (from the V8 bug report: The ECMAScript ⊃ JSON proposal shipped in V8 v6.6 and Chrome 66). And yet my Chrome version 79 does not parse "[01]", throws the same error as described in the article. Same error in Node 12.14.0 (which includes V8 7.7.299.13). Something doesn't add up.
Not sure what's confusing. "[01]" is not valid JSON. JSON being a subset of JavaScript means that all valid JSON constructs are valid JavaScript constructs. So, the subset statement says nothing at all about "[01]"
That said, in theory, shouldn't:
JSON.parse("0o10") === 8?
I get SyntaxError: Unexpected token o in JSON at position 1
Re:Unintuitive JSON Parsing
by ufedvjot13467 on Saturday December 28, 2019 @05:02PM
(#21902095)
No. Valid json is valid JavaScript. Valid JavaScript is not, necessarily, valid json.
Thanks, I misunderstood the proposal, which apparently applies mostly to "unescaped LINE SEPARATOR or PARAGRAPH SEPARATOR characters" within strings.
JSON.parse("(function() { })") doesn't parse either, despite being valid JavaScript. Both constructs are specific to JavaScript, and do not exist in JSON. Hence, JSON is a subset of JavaScript.