Wasabi
Wasabi

Reputation: 1591

JSON2.js or Native JSON Methods

JSON MDC

JSON ORG

Since the addition of the JSON methods(parse, stringify) listed at the Mozilla site, should these methods be used in lieu of the files from JSON.org(json2.js)?

Upvotes: 3

Views: 1677

Answers (2)

Brian Nickel
Brian Nickel

Reputation: 27560

You should use the native functions as they will get better performance and have a better memory footprint. Consider json2.js to be a polyfill, something you only use if the browser doesn't support JSON. A list of these browsers can be found here: http://caniuse.com/#search=JSON

if(!JSON || !JSON.parse || !JSON.stringify)
    document.write('<script src="json2.js"></script>');

Upvotes: 7

Slartibartfast
Slartibartfast

Reputation: 8805

Yes. Various javascript libraries already ask for native browser support before running parser in javascript. You can do it yourself by asking if there is global JSON object defined.

Upvotes: 1

Related Questions