JSON Syntax

JSON syntax is regarded as a subset of JavaScript syntax. In this tutorial, you will learn about writing JSON Syntax.

JSON Syntax Rules

  • Data is represented as name/value pairs and isolated by the comma.
  • Curly braces organize objects, and the colon isolates each name.
  • Square brackets hold the array, and commas separate values.

JSON Name / Value Pairs

A name/value pair is the name of a field, followed by a colon and value.

"userName" : "Alex"

It's easy to understand and equals to the Javascript statement:

userName = "Alex"

JSON Values

The following data types supported by JSON format:

TypeDescription
StringUse in double quotes
NumberMust be integer or floating point
ObjectA unordered collection of key: value pairs, used in curly brackets
ArrayOrdered sequence of values, used in square brackets
BooleanMust be true or false
nullFor empty value

JSON Objects

Objects can contain multiple keys: value pairs:

{
  "userName": "Alex",
  "userAge": 26
}

It's also easy to understand, and equals to the Javascript statement:

userName = "Alex" 
userAge = 26

JSON Arrays

An array can contain multiple objects:

{
  "students": [
    {
      "firstName": "Alex",
      "lastName": "Rodriguez"
    },
    {
      "firstName": "David",
      "lastName": "Crosby"
    },
    {
      "firstName": "Anna",
      "lastName": "Weston"
    }
  ]
}

In the above example, the object "students" is an array containing three objects, and each object is a record of students name.


Scroll Back to Top