JS: JSON Object

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.

[see JS: Data Types]

// type of JSON
console.log ( typeof JSON === "object" ); // true
console.log ( Object.prototype.toString.call( JSON ) === "[object JSON]" ) // true

The parent of JSON is Object.prototype. [see JS: Prototype and Inheritance]

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

Purpose of JSON

JSON is a static object.

JSON is not a function. You cannot call it, nor with new.

The purpose of JSON is as a namespace to hold functions, for working with the JSON data interchange format.

What's JSON Data Interchange Format?

JSON is a data interchange format.

JSON is basically 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

More about JSON syntax can be found here. http://www.json.org/

JavaScript Syntax vs JSON Syntax

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



[see JS: JSON.stringify]


[see JS: JSON.parse]


JSON[ Symbol.toStringTag ] → Value is the string "JSON".

[see JS: Determine Type of Object]

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

ECMAScript 2015 §Structured Data#sec-json-@@tostringtag


ECMAScript 2015 §Structured Data#sec-json-object

String Topic

  1. JS: Default Charset/Encoding
  2. JS: String Code Unit vs Code Point
  3. JS: Unicode Character Escape Sequence
  4. JS: Allowed Characters in Identifier
  5. HTML: Allowed Characters in id Attribute
  6. HTML: Character Sets and Encoding
  7. HTML/XML Entity List

  1. JS: Template String
  2. JS: Convert String to Number
  3. JS: Encode URL, Escape String
  4. JS: Format Number
  5. JS: JSON Object

  1. JS: String Object
  2. JS: String.prototype
  3. JS: String Constructor
Liket it? Put $1 at patreon.

Or, Buy JavaScript in Depth