JSON Data Format

By Xah Lee. Date: . Last updated: .

What is JSON

JSON Code Example

{
  "name": "Joe",
  "alive": true,
  "age": 25,
  "address": {
    "street": "1st Street",
    "state": "Cali"
  },
  "phone": [
    {
      "type": "home",
      "number": "123 456 7890"
    },
    {
      "type": "office",
      "number": "123 456 7890"
    }
  ],
  "children": [],
  "spouse": null
}

Difference Between JavaScript Syntax vs JSON Syntax

JSON syntax is more strict than JavaScript object/array syntax.

Key must be double quoted

// good
{"h":2}

// bad
// {h:2}

// bad
// {'h':2}

Does not allow extra comma at end

// good
{"h":2}

// bad
// {"h":2,}

Does not allow semicolon at the end

// good
{"h":2}

// bad
// {"h":2};

Does not allow undefined

JSON value does not allow undefined. (but null is ok)

// good
{"h":null}

// bad
// {"h":undefined}

Does not allow comment

JSON does not allow comment in JSON string or file. Some language may support it, some not.

JSON