Java JSON Tutorial - JSON Data Types

The following table lists the data types supported by JSON.

Type Description
Number double-precision, floating-point format in JavaScript. Octal and hexadecimal formats are not used. No NaN or Infinity. Example, 1,9, 0,-4. Fractions like .3, .9
Exponent like e, e+, e-,E, E+, E-
var json-object-name = { string : number_value}
String double-quoted Unicode with backslash escaping.
Escape sequence: \b \f \n \r \t \u
var json-object-name = { string : "string value"}
Boolean true or false
var json-object-name = { name: true/false,}
Array An ordered sequence of values.
Array elements are enclosed square brackets [element,element,element, ].
Value Can be a string, a number, true or false, null etc
Object An unordered collection of key:value pairs.
Object are enclosed in curly braces starts with '{' and ends with '}'.
key:value pairs are separated by ,
The keys must be strings and should be different from each other.
{ string : value, string1 : value1,.......}
Whitespace can be used between any pair of tokens
null empty


Example showing Number Datatype, value should not be quoted:

var obj = {grade: 97}

Example of String data type.

var obj = {name: 'abc'}

var obj = {name: 'Jack', 
           grade: 97, 
           pass: true}

The following JSON data has an array of three books.

  "books": [
   { "language":"Java" , "edition":"second" },
   { "language":"C++" , "edition":"fifth" },
   { "language":"C" , "edition":"third" }

Example showing Object:

 "id": "1",
 "language": "Java",
 "page": 500,