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
| Keyword | Purpose |
|---|---|
| type | Restricts the value to object, array, string, number, integer, boolean or null |
| properties | Describes each key of an object |
| required | Lists keys that must be present |
| enum / const | Limits a value to a fixed set or a single value |
| minimum / maximum | Numeric bounds |
| minLength / pattern | String length and regular-expression constraints |
| items | Schema applied to every element of an array |
| additionalProperties | Whether unknown keys are allowed |
| $ref | Reuses 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.
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
{
"$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
JSON
JSON is a lightweight text-based data format commonly used to exchange structured data between applications and APIs.
API
An API (Application Programming Interface) is a defined contract that lets one piece of software request data or actions from another without knowing how it works internally.
XML
XML (Extensible Markup Language) is a text format that describes data using nested, self-labelled tags, designed for documents and long-lived system-to-system messaging.
YAML
YAML is a whitespace-indented data format designed to be written and read by people, most often used for configuration files such as CI pipelines and Kubernetes manifests.
CSV
CSV (Comma-Separated Values) is a plain-text table format where each line is a row and each field is separated by a delimiter, usually a comma.
Base64
Base64 is an encoding scheme that represents binary data using 64 printable ASCII characters so it can travel safely through text-only channels.
Related tools
Related guides
Common JSON Errors and How to Fix Them
Decode the JSON parse errors you actually hit: unexpected token, trailing comma, unterminated string, BOM issues and duplicate keys — with the fix for each.
What Is JSON? A Plain-English Guide
JSON explained without jargon: what it is, how the syntax works, which data types it supports, where it is used and how it differs from JavaScript objects.
JWT Explained: Structure, Claims and Safe Use
What a JSON Web Token contains, how the three segments work, which claims matter, how signatures are verified and the mistakes that turn JWTs into a security hole.
CSV vs JSON: Choosing the Right Data Format
Compare CSV and JSON on structure, nesting, file size, streaming, typing and tooling, with clear guidance on which to use for exports, APIs and analytics pipelines.