JavaScript JS Tutorial JS Objects JS Functions JS Classes JS Async JS HTML DOM JS Browser BOM JS Web APIs JS AJAX JS JSON JS vs jQuery JS Graphics



JSON Data Types

JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy for humans to read and write and easy for machines to parse and generate. It is a text format that is completely language independent and can be used with any programming language. JSON is widely used in web applications to transmit data between the server and the client.

Brief Explanation of JSON Data Types

JSON has six data types:

  • String
  • Number
  • Boolean
  • Array
  • Object
  • null

String: A string is a sequence of zero or more Unicode characters, enclosed in double quotes. For example:

"Hello, World!"

Number: A number is a sequence of digits, optionally containing a decimal point, and an optional exponent. For example:

42
3.14
1.23e-4

Boolean: A boolean is either true or false. For example:

true
false

Array: An array is an ordered collection of zero or more values, enclosed in square brackets and separated by commas. For example:

[1, 2, 3]
["apple", "banana", "cherry"]
[true, false, true]

Object: An object is an unordered collection of zero or more name/value pairs, enclosed in curly braces and separated by commas. The name is a string and the value can be any JSON data type. For example:

{
  "name": "John",
  "age": 30,
  "isMarried": false
}

null: The null data type represents a null value. For example:

null

Code Examples

Here are some code examples of JSON data types:

String:

<p>{"message": "Hello, World!"}</p>

Number:

<p>{"count": 42}</p>

Boolean:

<p>{"isTrue": true}</p>

Array:

<p>{"fruits": ["apple", "banana", "cherry"]}</p>

Object:

<p>{"person": {"name": "John", "age": 30, "isMarried": false}}</p>

null:

<p>{"value": null}</p>

References

Activity