JSON Data Types
JSON supports exactly six data types, and understanding each one precisely prevents most parsing and validation mistakes.
The Six JSON Data Types
Every value in JSON must be one of six types: string, number, boolean, null, object, or array. There is no separate type for dates, functions, or undefined — a limitation that shapes how JSON is used in practice, as you'll see below.
- string — text wrapped in double quotes
- number — integer or floating-point, no quotes
- boolean — true or false, no quotes
- null — represents an intentionally empty value
- object — an unordered set of name/value pairs in { }
- array — an ordered list of values in [ ]
Strings and Numbers
Strings must use double quotes and support Unicode escape sequences like \n for newline, \t for tab, and \uXXXX for arbitrary Unicode characters. Numbers can be integers or decimals and may use scientific notation (e.g. 1.5e3), but JSON has no separate integer type — all numbers are just "number", and there is no support for values like NaN, Infinity, or hexadecimal literals.
String and Number Values
<!DOCTYPE html>
<html>
<body>
<h2>Result</h2>
<p id="demo"></p>
<script>
const data = {
"greeting": "Hello,\nWorld!",
"price": 19.99,
"quantityInStock": 250,
"discountRate": 1.5e-1
};
document.getElementById("demo").innerHTML = data.greeting;
</script>
</body>
</html>Booleans and Null
Boolean values are written as the bare, lowercase words true or false — never in quotes, and never capitalized like True or False as in some other languages. null represents a deliberate absence of a value, distinct from JavaScript's undefined, which cannot be represented in JSON at all.
Booleans and Null in Practice
<!DOCTYPE html>
<html>
<body>
<h2>Result</h2>
<p id="demo"></p>
<script>
const data = {
"emailVerified": true,
"newsletterOptIn": false,
"middleName": null
};
document.getElementById("demo").innerHTML = "Email verified: " + data.emailVerified;
</script>
</body>
</html>Objects and Arrays as Values
Because object and array are themselves valid JSON types, values can nest to represent hierarchical data: an array of objects, an object whose property is an array, or any combination thereof.
An Array of Objects
<!DOCTYPE html>
<html>
<body>
<h2>Result</h2>
<p id="demo"></p>
<script>
const data = {
"team": [
{ "name": "Nadia", "role": "Engineer" },
{ "name": "Owen", "role": "Designer" }
]
};
document.getElementById("demo").innerHTML = data.team[0].name + " - " + data.team[0].role;
</script>
</body>
</html>Type Comparison Table
Exercise: JSON Data Types
Which of these is a valid JSON data type?