JSON Schema is a declarative JSON dialect for annotating, validating, and establishing structural contracts for JSON documents and REST APIs.
JSON Schema is a declarative standard vocabulary written in JSON for annotating, validating, and enforcing structural constraints on JSON data documents. Standardized by the IETF JSON Schema Working Group across successive draft specifications (Draft 7, Draft 2019-09, Draft 2020-12), JSON Schema allows developers to describe allowed keys, mandatory properties, regex patterns, numeric thresholds, and array cardinality. It forms the backbone of OpenAPI contracts, API gateway validations, MCP tool definitions, and LLM structured outputs.
Explore and debug complex schemas interactively with the JSON Schema Visualizer & Tree Explorer, generate schema definitions automatically from sample payloads with our JSON to Schema Generator, generate strongly typed structs with JSON to Go, compile schemas to TypeScript with JSON to Zod, or test Model Context Protocol server definitions with our MCP Schema Validator.
| Specification | Details |
|---|---|
| Current Standard | JSON Schema Draft 2020-12 (IETF Internet-Draft) |
| Media Type | application/schema+json |
| Specification URI | https://json-schema.org/draft/2020-12/schema |
| File Extension | .json, .schema.json |
| Validation Engines | Ajv (JavaScript/TypeScript), jsonschema (Python), gojsonschema (Go) |
| Integration Ecosystem | OpenAPI 3.1, AsyncAPI, JSON-RPC, VS Code settings validation |
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://devflow.tools/schemas/user-profile.json",
"title": "UserProfile",
"type": "object",
"required": ["id", "username", "email", "roles"],
"properties": {
"id": {
"type": "string",
"format": "uuid",
"description": "Unique UUID identifier"
},
"username": {
"type": "string",
"minLength": 3,
"maxLength": 30,
"pattern": "^[a-zA-Z0-9_]+$"
},
"email": {
"type": "string",
"format": "email"
},
"age": {
"type": "integer",
"minimum": 18,
"maximum": 120
},
"roles": {
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "string",
"enum": ["admin", "editor", "viewer"]
}
}
},
"additionalProperties": false
}
| Keyword | Target Type | Validation Behavior |
|---|---|---|
type |
Any | Enforces primitive types: string, number, integer, boolean, array, object, null. |
required |
Object | Array of string key names that must be present. |
additionalProperties |
Object | Controls whether undeclared properties are permitted (false enforces strict payloads). |
enum |
Any | Constrains value to an explicit set of allowable literals. |
format |
String | Semantic validation checks (email, uri, date-time, uuid, ipv4). |
pattern |
String | Validates value against an ECMA-262 Regex. |
items / prefixItems |
Array | Enforces schemas for all array elements or tuple sequences. |
$ref |
Any | Reusable sub-schema pointer reference (e.g., "$ref": "#/$defs/Address"). |
import Ajv from 'ajv';
import addFormats from 'ajv-formats';
const ajv = new Ajv({ allErrors: true });
addFormats(ajv); // Adds email, uri, uuid format validators
const schema = {
type: 'object',
properties: {
sku: { type: 'string', minLength: 5 },
price: { type: 'number', minimum: 0.01 },
},
required: ['sku', 'price'],
additionalProperties: false,
};
const validate = ajv.compile(schema);
const testData = { sku: 'PROD-99', price: 19.99 };
if (validate(testData)) {
console.log('Valid JSON payload!');
} else {
console.error('Validation errors:', validate.errors);
}
Draft 2020-12 introduces major modernizations, including complete separation of vocabulary extensions, unified dynamic referencing ($dynamicRef), tuple array validation via prefixItems, and full alignment with the latest OpenAPI 3.1 specifications.
JSON Schema is a language-neutral, serializable JSON specification standard understood by backends written in Python, Java, Go, C#, or Rust. Zod is a TypeScript-first runtime validation library designed for developer ergonomics in Node.js and browser environments. You can easily cross-compile between both using our JSON to Zod Converter.
Yes. Modern AI models (OpenAI Structured Outputs, Anthropic, Gemini) consume JSON Schema definitions directly via their API parameters to guarantee that generated completions adhere strictly to your programmatic schema without hallucinated keys. Test schemas with our LLM JSON Schema Builder.
Free, browser-based utilities to test, generate, and inspect JSON Schema (Draft 2020-12) payloads directly.
Render Draft-07 / 2020-12 JSON Schemas into interactive visual trees, documentation diagrams, and realistic mock data.
Generate realistic fake JSON data from schemas, field templates, or sample data for testing and prototyping.
Generate TypeScript interfaces, Zod schemas, and Valibot schemas from JSON.
Convert JSON to C# classes with System.Text.Json or Newtonsoft serialization.
Convert JSON to Go structs with json tags and idiomatic naming.
Convert JSON to Zod schema definitions with automatic TypeScript type inference.
Repair and fix malformed JSON data from AI outputs, API responses, and copy-paste.
Generate JSON Schema for LLM structured outputs — OpenAI, Anthropic, Gemini, Ollama.
Validate, format, test, and debug Model Context Protocol (MCP) server schemas and tool definitions.