JSON Schema Tutorial

6 interactive lessons — paste real JSON, see live validation errors. Learn JSON Schema from scratch: types, string and number constraints, arrays, combining schemas, and building a full real-world API schema with $defs and $ref.

What Is JSON Schema?

JSON Schema is a vocabulary — itself expressed as JSON — for describing the structure, types, and constraints that another JSON document must satisfy. Instead of writing ad-hoc validation code ("check that age is a number, check that emaillooks like an email"), you declare those rules once, as data, and any JSON Schema-aware validator can enforce them consistently across your frontend, backend, and CI pipeline.

It shows up throughout the modern API ecosystem: OpenAPI embeds JSON Schema to describe request and response bodies, tools like Ajv and this site's own JSON Schema Validator use it to validate real payloads, and code generators use it to produce TypeScript interfaces, form UIs, and API client SDKs from a single source of truth. The specification has evolved through several drafts (04, 06, 07, 2019-09, 2020-12); this tutorial uses Draft 2020-12, the current stable version, throughout.

Unlike reading the spec top to bottom, every lesson here is a live playground: the schema and the data are both editable, and validation re-runs on every keystroke, so you see immediately which rule caught which mistake — the fastest way to build an intuition for how a validator actually reads a schema.

1Lesson 1 of 6

Your First Schema

Define structure, types, and required fields with JSON Schema

typepropertiesrequiredadditionalProperties
2Lesson 2 of 6

String Validation

Constrain strings with length, pattern, format, and enum

minLengthmaxLengthpatternformatenum
3Lesson 3 of 6

Numbers & Ranges

Validate numeric bounds, divisibility, and integer types

minimummaximumexclusiveMinimummultipleOfinteger
4Lesson 4 of 6

Arrays & Items

Validate array elements, length, and uniqueness

itemsminItemsmaxItemsuniqueItemscontains
5Lesson 5 of 6

Combining Schemas

Use allOf, anyOf, oneOf, and if/then/else for conditionals

allOfanyOfoneOfif/then/else
6Lesson 6 of 6

Real-World Schema

Compose complex schemas with $defs, $ref, and nested objects

$defs$refnested objectsfull API response

Frequently Asked Questions

Basic familiarity with JSON syntax (objects, arrays, strings, numbers) is enough. You don't need any prior JSON Schema experience — Lesson 1 starts from the "type" and "properties" keywords and builds up from there.

Every lesson uses Draft 2020-12, the current stable draft (referenced via "$schema": "https://json-schema.org/draft/2020-12"), which is what new APIs and tools should target. Lesson 6 notes the small keyword differences you'll see in older Draft-07 schemas (like "definitions" instead of "$defs").

No. JSON Schema is a general-purpose specification for describing the shape of any JSON document. OpenAPI (for describing REST APIs) embeds JSON Schema internally to describe request and response bodies, and JSON:API is a separate convention for structuring API responses — neither replaces JSON Schema, they build on top of it.

Each lesson takes roughly 5-10 minutes, including trying the challenge, so the full set of 6 lessons takes about 45-60 minutes. Because every example is live and editable, you can move at your own pace and revisit any lesson later.

They're built to be realistic starting points — the payment and order schemas in Lessons 5 and 6 mirror real API shapes — but always adapt field names, add descriptions, and test against your own real data using the JSON Schema Validator before shipping.

Try the JSON Schema Validator to test schemas against your own JSON, or the JSON Schema Generator to auto-infer a starting schema from an existing JSON document instead of writing one from scratch.

Ready to validate your own schemas?

Use these tools to validate and generate JSON Schemas for your real projects.