What is JSON Schema?

JSON Schema is a vocabulary that allows you to annotate and validate JSON data structures.

How it works

JSON Schema defines the shape, properties, data types, required fields, and format restrictions of JSON data payloads. OpenAPI 3.1 aligns directly with JSON Schema Draft 2020-12.

Example

JSON
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["id", "email"],
  "properties": {
    "id": { "type": "string" },
    "email": { "type": "string", "format": "email" }
  }
}

Common mistakes

  • Confusing JSON Schema keywords with OpenAPI 3.0 keywords
  • Omitting required arrays