JSON Syntax


Storing Data
When storing data, the data has to be a certain format, and regardless of where you choose to store it, text is always one of the legal formats. JSON makes it possible to store JavaScript objects as text.

JSON Syntax Rules
The JSON syntax is a subset of the JavaScript syntax. JSON syntax is derived from JavaScript object notation syntax:
{
  "employees": [
    { "firstName":"John",  "lastName":"Doe"   },
    { "firstName":"Anna",  "lastName":"Smith" },
    { "firstName":"Peter", "lastName":"Jones" }
  ]
}

JSON Data—a Name and a Value
JSON data is written as name/value pairs (aka key/value pairs). A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value:

"name": "John"

JSON—Evaluates to JavaScript Objects
The JSON format is almost identical to JavaScript objects. In JSON, keys must be strings, written with double quotes:

{ "name": "John" }

In JavaScript, keys can be strings, numbers, or identifier names:

{ name: "John" }       // JavaScript



Demonstration
The following demonstration shows how the script of HTML and JavaScript is displayed on the Web.

     





      Before you marry a person, you should first make them    
      use a computer with slow Internet to see who they really are.    
      — Will Ferrell