.schema.jsonapplication/schema+jsonSchemas, Validation & AI ContractsJSON Schema (Draft 2020-12 / Draft-07) (JSON Schema)
Cross-language API payload contracts, OpenAI/Anthropic Structured Outputs, form validation, and AJV verification.
JSON Schema is a declarative vocabulary (Draft 2020-12 / Draft-07) for annotating and validating JSON structures across languages, powering OpenAPI, AJV validators, and LLM structured outputs.
| Property | JSON Schema |
|---|---|
| File extension | .schema.json |
| MIME type | application/schema+json |
| Structure type | Typed Schema |
| Encoding | UTF-8 Text |
| Nesting support | Yes |
| LLM token efficiency | Medium |
| Schema / typed | Yes |
| Best for | Cross-language API payload contracts, OpenAI/Anthropic Structured Outputs, form validation, and AJV verification. |
Strengths
- Language-agnostic standard shared across TypeScript, Python, Go, Java, OpenAPI, and LLM APIs
- Expresses numeric ranges, regex patterns, enums,
$defs$refreuse,anyOf/oneOf, and strict object rules - Maps cleanly into runtime validators (Zod v4, Pydantic v2) and static TypeScript types
Trade-offs
- OpenAI Strict Structured Outputs forbid several Draft 2020-12 keywords like
minimumorformatunless normalized - Hand-authoring deeply nested
$defsandrequiredarrays is tedious without automatic inference - Different drafts (
Draft-07vs2020-12) use slightly different keywords (definitionsvs$defs)
Convert & inspect JSON Schema locally
Infer Draft 2020-12 or Draft-07 JSON Schema with nested types, formats, required arrays, and strict additionalProperties locally.
JSON Schema ValidatorValidate payloads against Draft 2020-12 or Draft-07 schemas locally with AJV and inspect exact JSON Pointer error paths.
JSON Schema to ZodCompile JSON Schema ($defs, $ref, enum, minimum, minLength, description) into idiomatic Zod v4 TypeScript code.
Transform JSON Schema specs (enum, minimum, description, $ref) into Python Pydantic v2 BaseModel classes with Field() bounds.
Compile JSON Schema into strict TypeScript .d.ts interfaces with union literals, optional ? props, and JSDoc comments.
Convert sample JSON into strict OpenAI response_format (strict: true, additionalProperties: false) or Anthropic Tool Use schemas.
Related engineering guides
How OpenAI Strict Mode, Anthropic Tool Use, Zod v4, and Pydantic v2 map through a Unified Type IR—and how to generate all three locally.
How to Repair Malformed & Truncated LLM JSON Outputs LocallyAutomatically strip markdown code fences, fix single quotes, trailing commas, Python True/False literals, and truncated brackets from LLM JSON responses.
OpenAPI to MCP: Exposing REST APIs as Model Context Protocol ToolsTurn internal OpenAPI 3.x YAML/JSON specs into Model Context Protocol (MCP) TypeScript tools and Zod v4 input schemas locally without uploading internal APIs.
JSON Schema Draft 2020-12 to Zod v4, Pydantic v2 & TypeScriptCompile Draft 2020-12 and Draft-07 JSON Schemas with $defs, $ref, enums, and bounds into Zod v4, Pydantic v2, and TypeScript interfaces locally via AJV & IR.
Related Comparisons
JSON Schema frequently asked questions
What is the difference between Draft 2020-12 and Draft-07?
Draft 2020-12 uses $defs and prefixItems for tuples, whereas older Draft-07 tooling expects definitions and array-form items.
Why do OpenAI Structured Outputs require additionalProperties: false?
Constrained decoding guarantees exact JSON compliance only when every object forbids unknown keys and lists every property in required (using nullable types for optional fields).
Can DataTo convert a JSON Schema into Zod or Pydantic code?
Yes. DataTo converts JSON Schema directly into Zod v4, Pydantic v2, and TypeScript .d.ts while preserving descriptions and enums.