Learn about the Different JSON Data Types Format

0
2674
JSON Data Types

In the last chapter, we discussed the basic syntaxes of JSON (JavaScript Object Notation) which are considered as a subset of the JavaScript syntax. In this chapter, we are going to discuss the various data types which are supported by JSON format.

JSON Data Types
The following are the data types which are supported by the JSON format.

S No.

Type

Description

1.

Number

It is a JSON data type which is used to represent a number. It is a double- precision floating-point format in JavaScript.

2.

String

It is a JSON data type which is used to represent a string. It is a double-quoted Unicode with backslash escaping.

3.

Boolean

It is a JSON data type which is used to represent a boolean value. It can be either true or false.

4.

Array

It is a JSON data type which is used to represent an array (i.e. collection of multiple values in an ordered sequence).

5.

Value

In JSON format, it can be of a string type, a number type, a boolean type (i.e. true or false), a null type, etc.

6.

Object

It is a JSON data type which is represented as an unordered collection of key and value pairs.

7.

Whitespace

It is a JSON data type which can be used between any pair of tokens.

8.

null

It is a JSON data type which is used to represent an empty value.

JSON Data Type – NUMBER
In JSON, the number datatype has the following properties.

• Number has a double precision floating-point format in JavaScript.
• In JSON format, the Octal and hexadecimal formats are not defined or used.
• There is no use of NaN (Not a Number) or Infinity number in JSON.
• Numbers in JSON can be further classified into the following types.

S No.

Number Type

Description

1.

Integer

Integers are numbers which are represented as digits 1-9 or 0. An integer can be either positive or negative.

2.

Fraction

Fractions are number such as .2, .7, etc.

3.

Exponent

Exponents are numbers such as e, e+, e-, E, E+, E-.

Syntax

Example

Output
When we execute above HTML code on browser then we will observe the following output.
subject_marks

JSON Data Type – STRING
In JSON, the string datatype has the following properties.

• String has a sequence of none or more than zero double quoted Unicode characters with backslash escaping.
• A character is a single character string which has a length as 1.
• JSON format permits to use the following special characters in string.

S No.

Number 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

Example

Output
When we execute above HTML code on browser, then we will observe the following output.
subject_grade

JSON Data Types – BOOLEAN
In JSON, the Boolean data type can have two values i.e. true or false.

Syntax

Example

Output
When we execute above HTML code on browser, then we will observe the following output.
subject_pass

JSON Data Types – ARRAY
In JSON, an array datatype has the following properties.

• An array is an ordered collection of values.
• An array is represented as an enclosure in square brackets i.e. begins with. [. and ends with.]…
• The values in an array are separated by, (comma).
• Indexing in an array can be started at 0 or 1.
• Arrays are recommended to be used when the key names are sequential integers.

Syntax

Example

JSON Data Types – OBJECT
In JSON, an object datatype has the following properties.

• It is JSON data type which is represented as an unordered collection of key and value pairs.
• Objects are enclosed with in the curly braces i.e. it starts with ‘{‘ and ends with ‘}’.
• Between each of the key and the value pair, a ‘:’ (colon) is present.
• The key and value pairs are separated by, (comma).
• Always, all keys must be strings and should be unique.
• Objects are recommended to be used when the key names are arbitrary strings.

Syntax

Example

JSON Data Types – WHITESPACE
It is a JSON data type which can be used between any pair of tokens. They are used to make the code more readable.

Syntax

Example
In the following example, we are going to demonstrate two declarations i.e. with and without whitespace.

JSON Data Types – NULL
It is a JSON data type which is used to represent an empty value.

Syntax

Example

JSON Data Types – VALUE
In JSON, a value could be a Number, String, Array, object, Boolean or Null.

Syntax

Example

Source code for the various data types of json format 

Conclusion: –
In this chapter, we discussed about the various data types available in JSON format along with the suitable examples.

LEAVE A REPLY

Please enter your comment!
Please enter your name here