JSON-Data Types
What is JSON? JSON_Syntax JSON_Data Types JSON_vs_XML JSON_Array JSON_Object
JSON uses the following data types.
Number:
- JSON follows double-precession floating point format which is represented in base 10(digits between 0-9) with no leading zeros.
- The number can be either positive or negative.
- Octal and hexadecimal formats are not allowed.
- The number can have a fractional part.
- It can have an exponent of 10 which is represented by e or E notation.
- NaN(Not a Number) or Infinity value is not valid.
Example:
{
"age" : 36,
"rate" : 250.50,
"speed" : 3.2E11,
}
Strings:
Strings consist of zero or more Unicode characters which are enclosed in double quotation marks(" ") or sequences of character enclosed with double quotation (" "). The strings with Single quotes ( ' ) are not valid.
Example:
{
"name" : "Anu"
}
Also includes escaped characters. Following are the list of backslash-escaped characters that are supported by JSON Strings.
\" | Double Quotation |
\\ | Backslash |
\/ | Forward slash |
\b | Backspace |
\f | Form feed |
\r | Carriage return |
\n | Newline |
\t | Tap |
\u | Hexadecimal digits |
Boolean:
The boolean value can be either True or False which is not surrounded by quotes.
Example:
{
"account" : True
}
Object:
The object in JSON is an unordered collection of name/value pairs.
Example:
{
"Student": { "name":" Aruna "," Roll NO " : "1235"," Dept ":" MBA "}
}
Array:
It is an ordered collection of values.
Example:
{
"Rate":[120,350,100]
"Color":["Red"," Blue ","Black ","Yellow "]
}
Null:
Null means no values/empty. If no value is assigned to any keys, it can be treated as a null type.
Example: { "Card":null, "Rank": , (null value is assigned automaticaly) "name":"Krish" }