3 ms·
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):
by tomstuart 15y ago
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):
> {"JSON":"rocks!"}
SyntaxError: Parse error
- gildas 15y agoRight, 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!"}
- nbpoole 15y agoIndeed. You get the same error in Chrome and a slightly different one in Firefox. That isn't valid JavaScript on its own.
- judofyr 15y agoThanks, I've updated the post: https://github.com/judofyr/timeless/commit/a8c9cf5a8c1df830a240e5fe66bbda68977d238a https://github.com/judofyr/timeless/commit/a8c9cf5a8c1df830a...
- tmcw 15y agoThough, to his credit, in the little REPL that he shows, he typed ({"JSON":"rocks!"}), not {"JSON":"rocks!"} - the former is valid.
- deleted 15y ago[deleted]
- deleted 15y ago[deleted]
- judofyr 15y agoTo 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.
- tomstuart 15y agoHN feature request: compare-and-swap comment semantics.
- lautis 15y ago> {"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.