What is a global JSON object?

I read that the best way to parse JSON in a browser is to use a method JSON.parse().

Sorry, I lived under a rock - where the hell did this global object come from JSON? Is this defined in some standard? Is it available in all browsers? When should you use Crockford json2.js instead?

+3
source share
1 answer

This is part of ECMAScript 5 and is an object with an internal JSON class that contains the appropriate methods ( stringifyand parse) for processing JSON data.

Use json2 library in browsers where JSON is not implemented.

You can check it as follows:

if( Object.prototype.toString.call( window.JSON ) !== '[object JSON]' ) {
    // load the library
}
+9
source

Source: https://habr.com/ru/post/1793142/


All Articles