iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

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

TypeExampleNotes
string"hello"Double quotes only.
number42, 3.14, -7, 1e5No NaN, no Infinity.
booleantrue, false
nullnullThe 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 valueWhat stringify does
undefinedDropped from objects; becomes null in arrays.
FunctionsSame — dropped / null.
SymbolsDropped.
DateSerialised as ISO string via toJSON().
Map / SetEmpty {} unless you add toJSON().
BigIntTypeError — convert to string first.
Cyclic referenceTypeError.

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": }

Test yourself

Q1. JSON does NOT support…
Q2. JSON.stringify(new Set([1,2])) returns…
Q3. BigInt and JSON.stringify…

Discussion

Loading…