JSON Syntax

Profile picture for user devraj

JSON syntax is basically considered as a subset of JavaScript syntax.

JSON Name Value Pairs

Name-value pairs have a colon between them as in "name" : "value".

JSON names are on the left side of the colon. They need to be wrapped in double quotation marks, as in “name”, and can be any valid string. Within each object, keys need to be unique.

JSON Value Data Types

Numbers: integer or floating point
String: double-quoted Unicode
Boolean: true or false
Array: an ordered sequence of values
Object: an unordered collection of key:value pairs
null: empty

JSON Separators/Tokens:

  • ":" to separate name from value
  • "," to separate name-value pairs
  • "{" and "}" for objects
  • "[" and "]" for arrays

Example

{
  "Actors": [
    {
      "name": "Tom Cruise",
      "age": 56,
      "Born At": "Syracuse, NY",
      "Birthdate": "July 3, 1962",
      "photo": "https://jsonformatter.org/img/tom-cruise.jpg",
      "wife": null,
      "weight": 67.5,
      "hasChildren": true,
      "hasGreyHair": false,
      "children": [
        "Suri",
        "Isabella Jane",
        "Connor"
      ]
    },
    {
      "name": "Robert Downey Jr.",
      "age": 53,
      "Born At": "New York City, NY",
      "Birthdate": "April 4, 1965",
      "photo": "https://jsonformatter.org/img/Robert-Downey-Jr.jpg",
      "wife": "Susan Downey",
      "weight": 77.1,
      "hasChildren": true,
      "hasGreyHair": false,
      "children": [
        "Indio Falconer",
        "Avri Roel",
        "Exton Elias"
      ]
    }
  ]
}