JavaScript: 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 JavaScript: 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 JavaScript: 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:

Properties


JSON.stringify

〔►see JavaScript: JSON.stringify

JSON.parse

〔►see JavaScript: JSON.parse

JSON[Symbol.toStringTag]

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

〔►see JavaScript: Determine Type of Object

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

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

Reference

ECMAScript 2015 §Structured Data#sec-json-object

String Topic

  1. JavaScript: Default Charset/Encoding
  2. JavaScript: String is 16-Bit Unit Sequence
  3. JavaScript: Unicode Character Escape Sequence
  4. JavaScript: Allowed Characters in Identifier
  5. HTML: Allowed Characters in id Attribute
  6. HTML: Character Sets and Encoding
  7. HTML/XML Entities

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

  1. JavaScript: String Object
  2. JavaScript: String.prototype
  3. JavaScript: String Constructor
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.