JSON in Plain English

JSON

 

 

JSON is an open standard, lightweight data-interchange format. It stands JavaScript Object Notation.

JSON is extremely common and useful in the modern webs for read and write on a website.  Before JSON, there is XML, which has much overhead and much more difficult to parse than JSON, which is not only easy for humans to read and write, but also easy for computer to parse.

JSON was derived from JavaScript, hence the name JavaScript Object Notation. However, it is a language-independent data format.

JSON always have file extension .json.

A simplest JSON contains a key and value:

{
  "color": "red"
}

A JSON key should always have double quotes around it.

Values can have a few of the basic types: string, number, float, boolean, and null. For instance:

{
  "String": "Hello",
  "Number": 1,
  "Float": 0.21,
  "Boolean": false,
  "Empty": null
}

The types are explanatory. Non-string values don’t require double quotes. It’s important to use comma after each value.

JSON also can have array as types. Array is made with brackets [ and ] with values in between separated with comma’s. For example:

{
  "colors":[ "red", "blue", "yellow" ]
}

JSON can also have objects . They are defined with curly brackets { and }. Objects as values in JSON must follow the same rules as JSON. In other words, you could have a JSON object inside another JSON object. This is called nesting.

JSON object example:

{
  "student":{ "name":"John""age":18 }
}

JSON nested object example:

{
  "student":{ "name":"John""age":18,
     "grades": { "math": 90, "english": 87 }  
   }
}

A complete syntax sample with all the data types discussed:

{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 27,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
},
"phoneNumbers": [
{
  "type": "home",
  "number": "212 555-1234"
},
{
  "type": "office",
  "number": "646 555-4567"
}
],
  "children": [],
  "spouse": null
}

Summary

JSON stands for JavaScript Object Notation. A JSON file is just a text file that stores data in files ended with .json extension. JSON data must conform the following data format:

  • Data is in name/value pairs
  • Data is separated by commas
  • Curly braces hold objects
  • Square brackets hold arrays

That’s all!

To learn more about JSON, I encourage you to check out the official JSON website!