JSON Syntax

Let’s discuss about JSON basic sytax. JSON syntax is primarily considered as a subset of JavaScript syntax.

JSON Syntax Rules

JSON syntax is as follows:


JSON Data (Name/Value pairs)

JSON data is specified as name/value pairs.

A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value:

“Language” : “JSON”

This is human readable and simply understood as:

Language = “JSON”

JSON Objects (Name/Value pairs)

JSON objects are mentioned inside curly brackets,

Objects can contain multiple name/values pairs or even array:

“Language”:”JSON” , “Author”:”Douglas Crockford”

JSON Arrays

JSON arrays are written inside square brackets.

An array can contain multiple objects:

{
“Languages”: [
{ “Language”:”C” , “Creator”:”Dennis Ritchie” },
{ “Language”:”C++” , “Creator”:”Bjarne Stroustrup” },
{ “Language”:”Java” , “Creator”:”James Gosling” }
]
}

Quick recap
  • Data is represented in name/value pairs
  • Curly braces hold objects and each name is followed by ‘:'(colon). The name/value pairs are separated by , (comma).
  • Square brackets hold arrays and values are separated by ,(comma).

Author: Udhay

Share This Post On

Pin It on Pinterest

Shares