Hacker News new | ask | show | jobs
by fletchowns 5479 days ago
Yes! I was shocked to see him recommend the use of a straight eval for parsing JSON.

json2.js is a must! JSON.parse and JSON.stringify are your friends.

https://github.com/douglascrockford/JSON-js/blob/master/json...

3 comments

Keep in mind that json2.js' JSON.parse() ultimately uses eval() after a few sanity checks. Definitely better than a blind eval(), but not quite the panacea it's often purported to be.
just pointing out to others although the parent probably already knew, but JSON.parse is native in all modern browsers, json2 is only needed if you support older browsers (ie7)
Holy crap, I did not know that.
Too my knowledge all browsers now ship with json built in -- if you must work with older browsers (not an entirely unreasonable requirement) you should check for the JSON object first, and if it isn't present load json2.js. Otherwise you're just adding an additional load penalty to your site (and on mobile browsers that can be 100s of milliseconds)
Json2.js does the check. However, it has to be loaded in order to be checked. Not a big issue if you are minifying and bundling all your js files before sending them to the browser client.