JSON Schema: From Basics to Production
There are many keywords, but only a dozen are used every day. Get type/properties/required/$ref right, handle error messages well, and you cover eighty percent of real cases.
Describe the shape of your data with JSON Schema, turn verbal agreements into executable validation, and let it drive TypeScript types and form generation in turn.
7 articlesThere are many keywords, but only a dozen are used every day. Get type/properties/required/$ref right, handle error messages well, and you cover eighty percent of real cases.
Types and schemas each cover one segment: one at compile time, one at runtime. The question isn't which to pick, but how to keep the two in sync automatically.
Generated schemas often block valid data. Learn why richer samples produce worse schemas, then the workflow: multi-record sampling, semantic completion, error pinpointing.
$ref solves reuse, allOf and oneOf solve composition, and stacking both is where things break. Covers $id, $defs, conditionals, recursion, bundling and debugging.
A validator emits machine errors; users want to know which input box is wrong. Covers the Ajv errors array, instancePath versus schemaPath, grouping and wording.
A passing validation does not mean clean data. Pydantic ignores unknown fields by default, Zod strips them, and Ajv lets them through — hallucinated parameters and typo'd keys all pass silently. This article shows the three forms of silent acceptance, then gives complete recipes for closing objects, controlling coercion, and tightening every nesting level.
A finished schema is where decay begins, not where work ends: one typo silently widens validation, one refactor breaks every fixture. This guide gives a workable contract testing setup — positive, negative, and snapshot fixtures, schema-first linting, compile-once reuse, and four CI gates that turn contract breakage into a red build.