JSON Syntax

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"
      ]
    }
  ]
}
Wed, 09/02/2020 - 03:13
Tarun Goswami is a highly experienced professional, currently serving as Technical Lead at a well-established IT services company. With over 12 years of experience across multiple domains, he demonstrates his expertise and passion for the industry through his engaging and informative blog writing in his spare time.

Comments