C.W.K.
Stream
Lesson 02 of 08 · published

The Six Types — and What's Missing

~10 min · json, types, spec

Level 0Plaintext
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Six values, no exceptions

JSON has exactly six value types: string, number, boolean, null, object, array. That is the entire vocabulary. Every JSON document, no matter how nested, is built from these six.

What JSON does NOT have

  • No undefined — JavaScript has it, JSON doesn't. Use null for missing values, or omit the key entirely.
  • No functions — JSON is data, not code.
  • No comments — Crockford removed them deliberately. Use a separate doc file or layered formats (JSON5, JSONC) if you need them.
  • No native dates — dates are strings, by convention ISO 8601 (2026-05-04T01:30:11Z).
  • No BigInt — numbers are IEEE 754 floats. Above 253, integers lose precision silently.
  • No regex, no Map, no Set — JS-specific types serialize as plain objects/arrays.

Implication: JSON is not a perfect mirror of any language

Every language has to map its native types onto JSON's six. Python's tuples become arrays. JavaScript's undefined becomes either null or absent. Dates become ISO strings. Round-tripping requires a convention, not just JSON.stringify.

The 'JSON has dates' lie: ECMAScript's JSON.stringify on a Date produces an ISO string; JSON.parse on that same string produces a string, not a Date. Round-trip fails. Use a reviver function or schema validation if you need real dates.

Code

All six types in one document·json
{
  "a_string": "hello",
  "a_number": 42,
  "a_boolean": true,
  "a_null": null,
  "an_object": { "nested": true },
  "an_array": [1, 2, 3]
}
What CAN'T appear in JSON (but does in JS)·javascript
// All of these die or change shape on JSON.stringify:
undefined         // becomes absent (object key) or null (array slot)
function(){}      // becomes absent
NaN, Infinity     // become null
123n              // BigInt — throws TypeError
new Date()        // becomes "2026-05-04T01:30:11.000Z" (string)
new Map()         // becomes {} (empty object)
new Set()         // becomes {} (empty object)
Symbol('x')       // becomes absent
Date round-trip with a reviver·javascript
const text = '{"created_at":"2026-05-04T01:30:11.000Z"}';
const data = JSON.parse(text, (key, value) => {
  if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T/.test(value)) {
    return new Date(value);
  }
  return value;
});
console.log(data.created_at instanceof Date);  // true

External links

Exercise

Take a Python dict (or JS object) you've serialized recently. List every type in it. For each type, ask: is this one of JSON's six? If not, what does it become on json.dumps / JSON.stringify? The mismatches are where round-trip bugs live.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.