JSON schema validation checks that a JSON response or document matches an agreed structure, including which fields exist, their data types and which are required. The expected structure is written as a JSON schema.
Why it matters: Schema checks catch changes to an API's response shape that would break consumers, without needing to assert on every individual value. They act as a safety net for the contract between an API and the applications that use it.
In practice: Teams write or generate a schema for each response, then validate real responses against it in their automated API tests. Many API testing frameworks include schema assertions out of the box.
Examples:
- Validating every response from an endpoint against its schema in an automated API test suite.
- Catching a release where a numeric ID quietly became a string.
Common pitfalls:
- Writing schemas so loose that almost any response passes.
- Letting schemas drift out of date, so tests check against a structure the API no longer promises.
Is JSON schema validation the same as contract testing? They're related. Schema validation checks the shape of responses. Contract testing goes further, checking that a provider and its consumers agree on how they interact.