Re:JSON: The JavaScript subset that isn't
by tomstuart on Sunday May 15, 2011 @12:21PM
(#2550184)
Valid point, but not a great example. You get a syntax error in Safari's Web Inspector even if you type that JSON yourself (i.e. no Unicode funny business):
[ Parent
| on HN ]
Right, you don't need "U+2028" character to reproduce the error. Why ? Because the parser handles {} as a block code, not as an object declaration.
Actually, the "good example" should be : var obj = {"JSON":"ro cks!"}
Thanks, I've updated the post: https://github.com/judofyr/timeless/commit/a8c9cf5a8c1df830a...
Though, to his credit, in the little REPL that he shows, he typed ({"JSON":"rocks!"}), not {"JSON":"rocks!"} - the former is valid.
To tomstuart's credit, I fixed the post after he wrote that comment.
Meta: Right after I originally wrote this comment I saw that tomstuart answered too, so I decided to delete my comment. Well, it appears that so did Tom, and suddenly there were no replies here.
HN feature request: compare-and-swap comment semantics.
Indeed. You get the same error in Chrome and a slightly different one in Firefox. That isn't valid JavaScript on its own.
> {"JSON":"rocks!"}
I don't think this is such a good point. While the example is not a valid expression, it is a perfectly good JS value/statement, like (almost) all other JSON. Wikipedia might go a bit too far in saying that all JSON formatted text is legal JS code, but (IMHO) it still is a perfectly good subset.The unicode part is a clear error and should be fixed.