In this tutorials, you will learn about the different data types supported by JSON values.
JSON Data Types
In JSON, data is represented as key/value pairs. The keys are strings(Text), and the values can be one of the following types:
1. String
Strings in JSON must be written in double quotes.
Example
The sample below shows a JSON String.
{
"name": "Rohatash",
"Email": "test@gmail.com"
}
2. Number
Numbers in JSON must be an integer, floating and scientific notation. JSON numbers support the following formats:
Example
The sample below shows a JSON Numbers.
{
"age": 25,
"salary": 35000.45,
"taxablesalary": 4.5e+6
}
3. Object
JSON objects are used to represent a collection of key-value pairs. The keys are strings, and the values can be any of the valid JSON data types.
Example
The sample below shows a JSON Object.
{
"FirstName" : "Rohatash",
"Age" : 35,
"Address" : "Mathura"
}
4. Array
An array is a collection or list of data as defined in other language. An array in JSON is a group of values that are separated by commas.
Example
The sample below shows a JSON Array.
{
"FirstName" : "Rohatash",
"Age" : "35",
"Address" : "Mathura"
"Qualification" : ["MCA", "BTech", "BCA"]
}
5. JSON Boolean
JSON supports two boolean values - true and false. It is important to note that the boolean values must be in lowercase and not enclosed in quotes.
Example
The sample below shows a JSON Boolean.
{
"isActive":true,
"isvalid":false
}
6. JSON Null
JSON supports a special value called null. It is used to represent a null value. Just like boolean values, null should also be in lowercase and not enclosed in quotes.
Example
The sample below shows a JSON Null.
{
"name": null,
"Qualification":null
}