skip to Main Content

I am following a tutorial which introduced the global JSON object to stringify objects, in the tutorial they mention that this JSON object and it’s methods is provided by the browser. I’ve also looked at the MDN page for JSON and they list it as a standard built in object.

I’m trying to understand if an object such as this is the same as the Date or Math objects and is built into Javascript or is it something extra that is provided by browsers implementing it?

2

Answers


  1. The JSON object is a built-in object in JavaScript that provides methods for converting JavaScript objects to and from JSON (JavaScript Object Notation) strings. This object is defined in the ECMAScript specification, which is the standard that defines the syntax and semantics of the JavaScript language.

    Unlike other built-in objects like Date and Math, the JSON object is not automatically available in all JavaScript environments. In some environments, such as web browsers, the JSON object is provided by the browser as a global object, which means it can be used without having to import any additional libraries or modules. In other environments, such as Node.js, the JSON object is not provided by default, and you will need to use require('json') to import it.

    In summary, the JSON object is a built-in object in JavaScript that is provided by some environments, such as web browsers, but not by others, such as Node.js. It is useful for converting JavaScript objects to and from JSON strings.

    Login or Signup to reply.
  2. Yes, it’s a built-in object that’s a property of the global object, as the specification requires for implementations of ECMAScript – just like Date and Math and many others.

    Generally, if you want to find whether a particular object or method is universal, see if the ES specification or DOM standard says anything about it. (That said, just because something’s in the standard doesn’t mean that it’ll be implemented everywhere – even some modern environments are not spec-compliant in a number of areas.)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search