JSON Data Types
JSON has a simple set of data types that are easy to understand and widely supported. These data types allow you to structure and represent various kinds of data in a clear and consistent way.
The following table describes each of the data type in JSON with examples.
Data Type | Description | Example |
---|---|---|
String | Text enclosed in double quotes | "name": "Alice" |
Number | Numeric values (integer or floating) | "age": 25 |
Boolean | Logical values: true or false | "isStudent": true |
Null | Represents no value | "middleName": null |
Object | Key-value pairs inside {} | "address": {...} |
Array | Ordered list of values inside [] | "hobbies": ["read", "travel"] |
The following diagram shows different data types in a JSON Object.
Let us see about each of these data types in a bit detail manner.
1. String
- Represents textual data.
- Enclosed in double quotes (
""
). - Can contain letters, numbers, and special characters.
Example:
</>
Copy
"name": "Arjun"
More about JSON Strings.
2. Number
- Represents numeric data.
- Can be an integer or a floating-point number.
- No quotes are used around numbers.
Example:
</>
Copy
"age": 30
"height": 5.8
More about JSON Numbers.
3. Boolean
- Represents a truth value.
- Can only be
true
orfalse
(without quotes).
Example:
</>
Copy
"isMarried": false
More about JSON Boolean.
4. Null
- Represents the absence of a value.
- The value is written as
null
(without quotes).
Example:
More about JSON Null.
</>
Copy
"middleName": null
5. Object
- Represents a collection of key-value pairs.
- Enclosed in curly braces
{}
. - Keys must be strings, and values can be any valid JSON data type.
Example:
</>
Copy
"address": {
"street": "123 Main St",
"city": "New York",
"zipCode": 10001
}
More about JSON Objects.
6. Array
- Represents an ordered list of values.
- Enclosed in square brackets
[]
. - Can contain any combination of JSON data types.
Example:
</>
Copy
"skills": ["JavaScript", "Python", "SQL"]
More about JSON Array.