What JSON Schema is
JSON Schema is a vocabulary for describing the expected shape of JSON data, written in JSON itself. A schema states which properties an object should have, what type each value must be, which fields are required, and which ranges, patterns, or formats are acceptable. A validator then checks a document against the schema and reports every place where it does not conform.
Schemas act as executable documentation. OpenAPI uses JSON Schema to describe request and response bodies, editors such as VS Code use it to provide autocomplete and warnings for configuration files, and backend services use it to reject malformed input before it reaches business logic.
Drafts and versions
JSON Schema has evolved through several published drafts. Draft-04 and draft-07 are still very common in older tooling. Draft 2019-09 introduced features such as unevaluatedProperties and replaced definitions with $defs, and draft 2020-12, the current version, reorganized array validation with prefixItems.
A schema declares its version in the $schema keyword. Keywords can behave differently between drafts, so always check that the validator you test with supports the same draft as the one your production system uses. A schema that passes in one draft can produce different results in another.
The keywords you will use most
The type keyword restricts a value to string, number, integer, boolean, object, array, or null. For objects, properties defines a sub-schema for each known key, required lists keys that must be present, and additionalProperties controls whether unknown keys are allowed. Setting additionalProperties to false is a simple way to catch typos in field names.
Strings can be constrained with minLength, maxLength, pattern for regular expressions, and enum for a fixed list of allowed values. Numbers use minimum, maximum, and multipleOf. Arrays use items to describe their elements, along with minItems, maxItems, and uniqueItems.
Schemas can be combined. allOf requires every listed sub-schema to match, anyOf requires at least one, oneOf requires exactly one, and not inverts a schema. Reusable pieces are stored under $defs and referenced with $ref, which keeps large schemas maintainable.
Reading errors and writing better schemas
Validation errors usually include two locations: the instance path, a JSON Pointer such as /user/address/zip identifying the failing value in your document, and the schema path identifying the rule that failed. Use the first to find the data and the second to understand the rule.
The format keyword, used for values like email, date-time, uri, and uuid, is treated as an annotation rather than a strict assertion by default in recent drafts. Many validators check formats anyway, but do not rely on format alone for security-sensitive input.
Generating a schema from a sample document is a fast way to start, but a generated schema only describes that one sample. Review it afterwards: mark truly optional fields as optional, add enums and ranges where the domain is known, and decide whether unknown properties should be rejected.
Where schema validation fits in a project
Validating at system boundaries gives the most value. Check incoming API requests and webhook payloads before processing them, validate configuration files when an application starts, and run contract tests in continuous integration to confirm that API responses still match the published schema. Catching a malformed payload at the edge produces a clear error message instead of a confusing failure deep inside the code.
Store schemas in version control next to the code that uses them, and evolve them carefully. Adding an optional property is backward compatible, while adding a new required property or tightening a type can break existing clients, so treat those changes like any other breaking API change.