JSON Syntax

The JSON punctuation is a subset of the JavaScript syntax.

JSON Syntax Rules

JSON punctuation is gotten from JavaScript object documentation syntax:

  • Data is in name/esteem pairs
  • Data is isolated by commas
  • Curly props hold objects
  • Square sections hold arrays

JSON Data - A Name and a Value

JSON information is composed as name/esteem pairs.

A name/esteem pair comprises of a field name (in twofold statements), pursued by a colon, trailed by a value:



JSON Values

JSON qualities can be:

  • A number (whole number or gliding point)
  • A string (in twofold quotes)
  • A Boolean (genuine or false)
  • An cluster (in square brackets)
  • An object (in wavy braces)
  • null

JSON Objects

JSON objects are composed inside wavy braces.

Just like JavaScript, JSON articles can contain different name/values pairs:


{"firstName":"John", "lastName":"Doe"}

JSON Arrays

JSON clusters are composed inside square brackets.

Just like JavaScript, a JSON cluster can contain different objects:


    {"firstName":"John", "lastName":"Doe"},
    {"firstName":"Anna", "lastName":"Smith"},

In the precedent over, the item "employees" is a cluster containing three objects. Each item is a record of an individual (with a first name and a last name).

JSON Uses JavaScript Syntax

Because JSON punctuation is gotten from JavaScript object documentation, next to no additional programming is expected to work with JSON inside JavaScript.

With JavaScript you can make a variety of items and relegate information to it, as this:


var representatives = [
    {"firstName":"John", "lastName":"Doe"},
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter","lastName": "Jones"}

The first passage in the JavaScript object exhibit can be gotten to like this:


/returns John Doe
employees[0].firstName + " " + employees[0].lastName;

It can likewise be gotten to like this:


/returns John Doe
employees[0]["firstName"] + " " + employees[0]["lastName"];

Data can be altered like this:


employees[0].firstName = "Gilbert";

It can likewise be altered like this:


employees[0]["firstName"] = "Gilbert";

In the following section you will figure out how to change over a JSON content to a JavaScript object.

JSON Files

  • The record type for JSON documents is ".json"
  • The MIME type for JSON content is "application/json"