Table of Contents
From above example, we can derive following:
- JSON Data is in name value pair (e.g. “name”: “Batman”)
- JSON Data are separated via commas
- Curly braces hold JSON objects
- Square brackets hold JSON arrays
- JSON values can be one of the following:
- a string (written within double or single quotes [e.g. “Batman” or ‘Batman’, both are correct])
- a number (written without any quote e.g. “age”: 53)
- an object (JSON object e.g. “Emp_detail” here is an object)
Note: We can even have an array of object or object of arrays. If an object has multiple arrays, it will be called object of arrays. And if, an array includes multiple objects, it will be called an array of objects. We will learn more about this in upcoming assignment section.
- an array (JSON array e.g. “powers” here is an array)
Note: We can even have an array of array i.e. array inside an array. We will learn more about this in upcoming assignment section.
- a Boolean (It can have true or false as a value, e.g. “active”)
- null (It can be also assigned, if values are not available; e.g. Middle name for a person can be a null)
In generic, JSON syntax can be defined as below:
Here, name can be any unique string, and value can be either a string, number, array or object.
A JSON data can be used to load data into a table or wherever required. Below you can find the output for the JSON we have mentioned in the intro part of JSON: