3 ms·
No you can't, JSON is not JavaScript and eval is not capable of working on all correct JSON documents. JSON requires a JSON specific parser. So this breaks no
by gnaritas 12y ago
No you can't, JSON is not JavaScript and eval is not capable of working on all correct JSON documents. JSON requires a JSON specific parser. So this breaks nothing, eval doesn't work now and JSON has never been JavaScript.
- otterley 12y agoWhen JSON was first used, it was evaluated with eval. Certain issues might cause JSON not to evaluate properly (the only article I could find arguing that it's not Javascript involve Unicode issues that are rarely encountered), but it doesn't invalidate my point.
- draegtun 12y agoAnd to back up gnaritas comment... JSON: The JavaScript subset that isn't - http://timelessrepo.com/json-isnt-a-javascript-subset http://timelessrepo.com/json-isnt-a-javascript-subset
- deleted 12y ago[deleted]
- ninjaplease 12y agoLook, you're just wrong. The only exception to "eval" is some obscure unicode bug others are mentioning. JSON is literally a JS object literal (with the additional requirement that any key be a string). There's also no reason to use eval when JSON.parse will do it safely.
- gnaritas 12y agoNo I'm not wrong and there mere fact that you mention the exception means you've conceded my point; and those aren't bugs, they're in the spec which means it was never a subset of JS. > JSON is literally a JS object literal (with the additional requirement that any key be a string). Which makes it not a JS object literal but a near subset with slightly different rules with unicode strings that make it not even a subset.
- ninjaplease 12y agoWhat spec are you looking at? http://www.ietf.org/rfc/rfc4627.txt http://www.ietf.org/rfc/rfc4627.txt specifically says in section 2.5 that all unicode characters are meant to be supported. So now you're wrong twice.
- gnaritas 12y agoTry learning something jackass: http://timelessrepo.com/json-isnt-a-javascript-subset http://timelessrepo.com/json-isnt-a-javascript-subset