I'm reading that the best way to parse JSON in the browser is by using the JSON.parse() method.
Sorry, I've been living under a rock — where the hell did this JSON global object come from? Is it defined in some standard? Is it available in all browsers? When should I use Crockford's json2.js instead?
It is part of ECMAScript 5, and is the Object with the internal class JSON that holds relevant methods (stringify and parse) for processing JSON data.
Use the json2 library in browsers where JSON is not implemented.
You could test for it like this:
if( Object.prototype.toString.call( window.JSON ) !== '[object JSON]' ) {
// load the library
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With