A JSON document that describes the shape of other JSON documents
JSON Schema is itself JSON. You write a schema document, point a validator at a data document, and get back a 'valid' or a list of violations. The current dialect is Draft 2020-12 (informally just 'JSON Schema'). Earlier drafts (Draft-07, Draft-04) are still everywhere — read the $schema URI to know which.
Three things JSON Schema gives you
- Validation — confirm a document matches a contract. Used at API edges, on config load, in CI.
- IDE autocomplete — VS Code reads schemas from
schemastore.organd gives you autocomplete + inline docs inpackage.json,tsconfig.json,.eslintrc.json,github-actions.yml, etc. - Documentation — schemas are docs. Tools like Redoc render OpenAPI schemas as a navigable site.
The smallest useful schema
'Any object with a string name' is enough to get a feel.
Principle: a schema is the place to encode invariants you'd otherwise enforce in code review. 'name is required, slug must match this regex, version follows semver' belongs in the schema, not in a wiki page nobody reads.