JavaScript JSON Values
JSON can represent six types of values.
A JSON value can be a string, number, boolean, null, object, or array.
JSON Value Types
The table below lists all JSON value types.
| Type | Example |
|---|---|
| String | "John" |
| Number | 30 |
| Boolean | true |
| Null | null |
| Object | {"name":"John"} |
| Array | ["red","green"] |
JSON Strings
A JSON string is a sequence of characters enclosed in double quotes.
Example
{
"name": "John"
}
JSON strings always use double quotes.
JSON Numbers
JSON numbers can be integers or floating-point numbers.
Example
{
"age": 30,
"height": 1.82
}
JSON does not distinguish between integers and floating-point numbers.
JSON Booleans
JSON supports the Boolean values true and false.
Example
{
"member": true,
"student": false
}
JSON Null
The value null represents an empty value.
Example
{
"middleName": null
}
JSON Objects
A JSON object is enclosed in curly braces.
A JSON object contains one or more name/value pairs.
Example
{
"name": "John",
"age": 30,
"city": "New York"
}
Names must be strings enclosed in double quotes.
Values can be any valid JSON value.
JSON Arrays
A JSON array is enclosed in square brackets.
An array contains an ordered list of values.
Example
[
"Ford",
"Volvo",
"BMW"
]
Array values can be any valid JSON value.
Nested Values
Objects and arrays can contain other objects and arrays.
Example
{
"name": "John",
"age": 30,
"address": {
"city": "New York",
"country": "USA"
},
"hobbies": [
"Reading",
"Cycling",
"Photography"
]
}
Nested objects and arrays make it possible to represent complex data structures.
Unsupported Values
Some JavaScript values cannot be represented in JSON.
| JavaScript Value | Supported in JSON |
|---|---|
undefined |
No |
| Functions | No |
Symbol |
No |
BigInt |
No |
NaN |
No |
Infinity |
No |
These values must be converted before they can be stored as JSON.