JSON Schema basics

JSON Schema basics: validate the shape of JSON

JSON validates syntax (is it parseable). JSON Schema validates structure (does it match what your API expects).

What JSON Schema is for

A small example

Example JSON:

{
  "id": 42,
  "email": "[email protected]",
  "role": "admin",
  "active": true
}

Example schema (simplified):

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "additionalProperties": false,
  "required": ["id", "email", "role"],
  "properties": {
    "id": { "type": "integer", "minimum": 1 },
    "email": { "type": "string", "format": "email" },
    "role": { "type": "string", "enum": ["admin", "editor", "viewer"] },
    "active": { "type": "boolean" }
  }
}

Key concepts

How this helps in practice

If you receive “valid JSON but wrong data”, schema validation tells you which field is missing or wrong—much faster than manual debugging.

Related: Validate JSON syntax · API JSON best practices