JSON Data Types
JSON supports six value types — a strict subset of what JavaScript can express. Knowing the list avoids parse errors and silent drops.
The six allowed values
| Type | Example | Notes |
|---|---|---|
| string | "hello" | Double quotes only. |
| number | 42, 3.14, -7, 1e5 | No NaN, no Infinity. |
| boolean | true, false | — |
| null | null | The lone "no value" placeholder. |
| array | [1, "two", null] | Mixed types allowed. |
| object | { "name": "Ada" } | Key always a double-quoted string. |
What JS has but JSON doesn't
| JS value | What stringify does |
|---|---|
undefined | Dropped from objects; becomes null in arrays. |
| Functions | Same — dropped / null. |
| Symbols | Dropped. |
| Date | Serialised as ISO string via toJSON(). |
| Map / Set | Empty {} unless you add toJSON(). |
| BigInt | TypeError — convert to string first. |
| Cyclic reference | TypeError. |
Examples
JS
JSON.stringify({ a: 1, b: undefined, c: () => 2 });
// '{"a":1}'
JSON.stringify([1, undefined, function(){}]);
// '[1,null,null]'
JSON.stringify({ when: new Date() });
// '{"when":"2026-06-06T12:00:00.000Z"}'
JSON.stringify(new Set([1, 2, 3]));
// '{}'
JSON.stringify(123456789012345678901234567890n);
// TypeError: Do not know how to serialize a BigInt
Tip: Pass a custom
toJSON() on your classes to control the shape they produce — the simplest way to make domain types serialise cleanly.Example
Example
<!DOCTYPE html>
<html>
<body>
<p id="out"></p>
<script>
document.getElementById("out").textContent = "Hello from JSON Data Types!";
</script>
</body>
</html>
Try it Yourself »
Exercise
Set the value JSON uses for "no value".
{ "manager":
}
Four letters.
Discussion
Loading…