⌘K

Data Formats

JSON Schema

JSON Schema is a declarative vocabulary, itself written in JSON, that describes the expected structure, types and constraints of a JSON document so it can be validated automatically.

Updated 12 Aug 2026

Why schemas exist

A JSON parser only tells you whether text is syntactically valid. It cannot tell you that `age` must be a positive integer, that `email` is required, or that `status` may only be one of three strings. JSON Schema fills that gap: it is a contract, written in JSON, that a validator checks documents against.

Core keywords

KeywordPurpose
typeRestricts the value to object, array, string, number, integer, boolean or null
propertiesDescribes each key of an object
requiredLists keys that must be present
enum / constLimits a value to a fixed set or a single value
minimum / maximumNumeric bounds
minLength / patternString length and regular-expression constraints
itemsSchema applied to every element of an array
additionalPropertiesWhether unknown keys are allowed
$refReuses a schema defined elsewhere

Where schemas are enforced

  • API gateways rejecting malformed request bodies before they reach business logic
  • Editors such as VS Code, which autocomplete package.json and CI config from published schemas
  • Data pipelines validating events before they land in a warehouse
  • OpenAPI documents, which describe request and response bodies with JSON Schema

Set additionalProperties to false while developing. It surfaces typos in keys immediately instead of silently ignoring them.

JSON Validator

Check syntax first, then apply your schema with confidence.

Try JSON Validator

Characteristics

  • Written in JSON, so schemas are themselves machine-readable
  • Versioned by draft (Draft 7 and 2020-12 are the common ones)
  • Composable through $ref, allOf, anyOf and oneOf
  • Annotation keywords such as title, description, default and examples feed documentation and editors

Common uses

  • Validating API request and response payloads
  • Powering editor autocomplete and inline documentation
  • Generating TypeScript types, forms and documentation from one source
  • Contract testing between services

Advantages

  • One contract shared by producers, consumers, editors and documentation
  • Catches malformed data at the edge instead of deep inside application code
  • Mature tooling in every major language
  • Human-readable error messages pointing at the exact failing path

Limitations

  • Verbose for deeply nested structures
  • Draft differences cause subtle incompatibilities between validators
  • format keywords such as email are only advisory in some validators
  • Cannot express cross-field business rules cleanly

Examples

A schema requiring an id and a valid email, with an optional role
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["id", "email"],
  "additionalProperties": false,
  "properties": {
    "id": { "type": "integer", "minimum": 1 },
    "email": { "type": "string", "format": "email" },
    "role": { "type": "string", "enum": ["admin", "editor", "viewer"] }
  }
}

Frequently asked questions

What is JSON Schema used for?

Validating that a JSON document has the expected keys, types and value ranges before an application relies on it.

Is JSON Schema part of the JSON standard?

No. JSON defines syntax only; JSON Schema is a separate specification built on top of it.

JSON Schema or TypeScript types?

TypeScript checks at compile time inside your codebase; JSON Schema checks real data at runtime, including data from other systems.

Which draft should I use?

Draft 2020-12 for new projects, unless a library you depend on only supports Draft 7.

Can I generate a schema from existing JSON?

Yes, inference tools produce a starting schema, but you should tighten required fields and enums by hand.

Related terms

All terms

Related tools

Related guides

All guides