JavaScript: JSON

By Xah Lee. Date: . Last updated: .

JSON is the value of the property key "JSON" of the Global Object.

console.log( window["JSON"] === JSON ); // true


Type of JSON is Object .

console.log( typeof JSON === "object" ); // true

console.log( JSON ) === "[object JSON]" ) // true


Parent of JSON is Object.prototype. [see Prototype and Inheritance]

console.log( Reflect.getPrototypeOf ( JSON ) === Object.prototype ); // true


Purpose of JSON is as a namespace, for functions working with the JSON data interchange format.

What is JSON Data Interchange Format?

JSON is a data interchange format.

JSON is a more strict syntax of nested JavaScript object or array. Used to pass data to the web browser, or exchange data with other language, API.

For example, here's a JSON:

  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 25,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  "phoneNumbers": [
      "type": "home",
      "number": "212 555-1234"
      "type": "office",
      "number": "646 555-4567"
  "children": [],
  "spouse": null

JavaScript Syntax vs JSON Syntax

JSON syntax is more strict than JavaScript syntax. For example:

bad. JSON does not allow unquoted property key.
bad. JSON does not allow single quote.
bad. JSON does not allow extra comma at end.
bad. JSON value does not allow undefined. (but null is ok)


JavaScript in Depth

JS Obj Reference