This Angular tutorial helps you get started with Angular quickly and effectively through many practical examples.

JSON DataTypes


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:

Json Data Types

  1. String
  2. Number
  3. Object
  4. Array
  5. Boolean
  6. Null

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:

  • Integer -(Ex-1,2,4)
  • Floating point -(Ex- 35000.45)
  • Scientific notation -(Ex- 4.5e+6))

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
}

Prev Next