Skip to main content

JSON Schema

JSON Schema is a specification for describing the structure, types, and constraints of JSON data — what fields are required, what types they must be, valid value ranges — used in testing to automatically validate that an API response matches its documented contract, rather than checking each field by hand.

Instead of writing a separate assertion for every field in a response ("check id is a number," "check email is a string," "check status is one of these three values"), a JSON Schema captures all of those rules in one declarative document, and a single schema-validation assertion checks the entire response against it at once.

This scales especially well for large or frequently changing APIs — updating the schema when a field is added or a type changes is far less work than updating dozens of individual hand-written assertions scattered across a test suite, and the schema itself can double as living API documentation.

Example

{
  "type": "object",
  "required": ["id", "email", "status"],
  "properties": {
    "id": { "type": "integer" },
    "email": { "type": "string", "format": "email" },
    "status": { "enum": ["active", "suspended", "pending"] }
  }
}

A JSON Schema validating the shape of a user object in one declaration.

JSON Schema — Definition, Example & How It's Used | QA Bash Glossary | QA Bash