JSON Data - In JSON, the data are in key/value pairs. Key and value is separated by a colon :
. JSON value must be of the following data types:String
, Number
, Object (JSON object)
, Array
, Boolean
, NULL
Please keep in mind that JSON value does not support the following data types: function
, date
,
undefined
.
Let us understand each of the data types.
JSON value having data type string, must be written inside the double quotes.
Source Code
<script type="text/javascript">
'{"game":"cricket","event":"mumbai"}'
</script>
JSON value having data type number must be written without double quotes and it will be of integer or floating-point.
Source Code
<script type="text/javascript">
'{"name":"rice","price":50}'
</script>
JSON data value type might be an object.
Source Code
<script type="text/javascript">
{"users":{"name":"Smith", "age":45, "city":"Gorakhpur"}}
</script>
JSON data value can be array. Let us understand it with the help of an example
Source Code
<script type="text/javascript">
{
"uesrs":["Smith", "Jane", "Doe"]
}
</script>
JSON data value can be either true or false.
Source Code
<script type="text/javascript">
{"test":true}
</script>
JSON data value can be null.
Source Code
<script type="text/javascript">
{"test":null}
</script>