Everything you need to know about JSON
JSON (JavaScript Object Notation, .json) is the lingua franca of modern web APIs. Created by Douglas Crockford in 2001 (specified in RFC 8259 / ECMA-404), its appeal is brutal simplicity: six data types (string, number, boolean, null, array, object) and no schemas, no namespaces, no comments. The format that XML wished it could be.
How it works under the hood
- Six types only. Strings (Unicode, double-quoted), numbers (no NaN, no Infinity, no leading zeros), booleans, null, arrays (heterogeneous), and objects (string keys, any value).
- Strictly Unicode. Per RFC 8259, JSON files must be UTF-8 encoded by default (UTF-16 and UTF-32 also legal but rare). Always serve `Content-Type: application/json; charset=utf-8`.
- Number precision. JSON numbers are IEEE 754 doubles in practice, meaning integers above 2^53 lose precision. Use strings for IDs, timestamps in nanoseconds, and bigint values.
- No trailing commas, no comments. This is intentional - the spec optimizes for machine generation/parsing, not hand editing. For comments, use JSON5 or JSONC (TypeScript config files).
Where you'll actually use it
- REST API responses (universal across frameworks)
- Configuration files (package.json, tsconfig.json, every modern build tool)
- Logging and structured event streams (JSON Lines / NDJSON: one object per line)
- Data interchange between languages where types don't map cleanly
How it compares to alternatives
JSON vs YAML: YAML is human-friendlier (comments, no quotes) but has hidden footguns (the famous Norway problem where 'NO' becomes false). JSON vs XML: JSON is more compact and natively maps to JavaScript - but XML has schemas, namespaces, and tools like XPath. JSON vs MessagePack/Protobuf: Binary formats are 30-90% smaller and 10x faster to parse, but lose human readability.
Things that will trip you up
- Date/time has no native type - use ISO 8601 strings and parse them at the boundary
- Don't trust JSON numbers for money - use strings or fixed-precision libraries
- Streaming parsing requires special tools (Oboe.js, Jackson streaming) - default parsers load the whole document