

Ask HN: Trusted JSON Parser, why doesnt browsers themselves provide one? - digamber_kamat

I write many Firefox plug-ins and other JavaScript code where I have to deal with lots of JSON data.<p>The real strength of JSON data while using it with JS is that you dont have to bother much about parsing it, which is a real headache if you are using XML.<p>But then most of the code reviewers including JSLint display "eval" as unsafe. I then end up using Jquery, prototype etc to parse it.<p>I wanted to know if there is a better way. Why dont browesrs provide a safe alternative to eval? And parsing it by custom doesnt make it 100% safe either.
======
yannis
You can check if native JSON is available by:

    
    
         if (typeof(JSON) === 'object') { 
                alert('native JSON may be available.');
          }
    
    

Three major browsers already include support for native JSON parsing: IE8,
Firefox 3.5, and Chrome 3.

Safari 4 does not currently support the standard, but its underlying engine
(WebKit) has recently implemented it. Hopefully the feature will make its way
to Safari soon.

