Sr.No. | Type & Description |
1 | Number double-precision floating-point format in JavaScript |
2 | String double-quoted Unicode with backslash escaping |
3 | Boolean true or false |
4 | Array an ordered sequence of values |
5 | Value it can be a string, a number, true or false, null, etc |
6 | Object an unordered collection of key: value pairs |
7 | Whitespace can be used between any pair of tokens |
8 | null empty |
JSON values must not be one of the below-given data types:
Number
The following table indicates the number types−
Sr.No. | Type & Description |
1 | Integer Digits 1-9, 0, and positive or negative |
2 | Fraction Fractions like .3, .9 |
3 | Exponent Exponents like e, e+, e-, E, E+, E- |
Syntax
var json-object-name = { string : number_value, .......}
Example
Example representing the Number Datatype, the value must not be quoted:
var obj = {marks: 97}
String
The table indicates numerous unique characters that you may use in strings of a JSON document:
Sr.No. | Type & Description |
1 | " double quotation |
2 | \ backslash |
3 | / forward slash |
4 | b backspace |
5 | f form feed |
6 | n new line |
7 | r carriage return |
8 | t horizontal tab |
9 | u four hexadecimal digits |
Syntax
var json-object-name = { string : "string value", .......}
Example
String Datatype Example is given below:
var obj = {name: 'Amit'}
Boolean
It comprises two and more values.
Syntax
var json-object-name = { string : true/false, .......}
Example
var obj = {name: 'Amit', marks: 97, distinction: true}
Array
Syntax
[ value, .......]
Example
In the below given example it represents an array containing multiple objects:
{ "books": [ { "language":"Java" , "edition":"second" }, { "language":"C++" , "lastName":"fifth" }, { "language":"C" , "lastName":"third" } ] }
Object
Syntax
{ string : value, .......}
Example
Example showing object
{ "id": "011A", "language": "JAVA", "price": 500, }
WhiteSpace
It may be inserted between any pair of tokens. It can be added to make a code more readable. The example indicates statement with and without whitespace −
Syntax
{string:" ",....}
Example
var obj1 = {"name": "Sachin Tendulkar"} var obj2 = {"name": "SauravGanguly"}
Null
It simply means an empty type
Syntax
null
Example
var i = null; if(i == 1) { document.write("<h1>value is 1</h1>"); } else { document.write("<h1>value is null</h1>"); }
JSON Value
It consists of −
Syntax
String ' Number ' Object ' Array ' TRUE ' FALSE ' NULL
Example
var i = 1;
var j = "Sachin";
var k = null;