JSON Schema 2020-12: A Practical Validation Guide
JSON Schema 2020-12 is the current draft and the default for MCP tool schemas. Learn the core keywords, common mistakes and how to validate JSON online.
JSON Schema 2020-12 is the current version of the JSON Schema standard: a JSON document that describes which types, fields and values another JSON document may contain. You declare it with "$schema": "https://json-schema.org/draft/2020-12/schema", validate with a library such as Ajv, and fix errors by JSON path. Try schemas in the free JSON Schema validator.
Which JSON Schema version should I use in 2026?
Use 2020-12 for new work. The official specification page states: "The current version is 2020-12! The previous version was 2019-09." Draft-07 is still everywhere in older OpenAPI tooling and tutorials, and plenty of validators default to it, but new protocols have moved on.
The clearest example is the Model Context Protocol. In the 2026-07-28 MCP tools spec, both inputSchema and outputSchema default "to 2020-12 if no $schema field is present." Draft-07 is still allowed if you declare it explicitly. If you build MCP servers, your tool schemas are 2020-12 whether you planned it or not. Our MCP 2026-07-28 changes post covers the rest of that release.
What does a 2020-12 schema look like?
Here is a realistic order schema that uses the keywords you will reach for most often: type, required, properties, enum, pattern, minimum, format, a reusable definition under $defs, and a tuple with prefixItems.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/schemas/order.json",
"type": "object",
"required": ["id", "email", "items"],
"properties": {
"id": { "type": "integer", "minimum": 1 },
"email": { "type": "string", "format": "email" },
"status": { "enum": ["pending", "paid", "shipped"] },
"items": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/$defs/item" }
},
"coords": {
"type": "array",
"prefixItems": [{ "type": "number" }, { "type": "number" }],
"items": false
}
},
"additionalProperties": false,
"$defs": {
"item": {
"type": "object",
"required": ["sku", "qty"],
"properties": {
"sku": { "type": "string", "pattern": "^[A-Z]{3}-\\d{4}$" },
"qty": { "type": "integer", "minimum": 1 }
},
"additionalProperties": false
}
}
}coords is a tuple: prefixItems describes position 0 and 1, and "items": false forbids anything after them. In draft-07 you would have written "items": [...] plus additionalItems. That change catches more people than any other.
How do I validate JSON against a 2020-12 schema?
In JavaScript, use Ajv, and import the 2020-12 build. The default ajv export targets draft-07. Pass it the schema above and it fails before validating anything:
Error: no schema with key or ref "https://json-schema.org/draft/2020-12/schema"The fix is one import. format checks need the separate ajv-formats plugin, and allErrors returns every problem instead of stopping at the first:
import Ajv2020 from "ajv/dist/2020";
import addFormats from "ajv-formats";
const ajv = new Ajv2020({ allErrors: true });
addFormats(ajv);
const validate = ajv.compile(orderSchema);
const ok = validate(order);
if (!ok) console.log(validate.errors);Running this with Ajv 8.20.0 against a deliberately broken order:
// Input
{ "id": 0, "email": "not-an-email", "status": "lost",
"items": [{ "sku": "abc-1", "qty": 2 }],
"coords": [59.3, 18.1, 7], "note": "x" }
// validate.errors (instancePath, keyword, message)
"" additionalProperties must NOT have additional properties
"/id" minimum must be >= 1
"/email" format must match format "email"
"/status" enum must be equal to one of the allowed values
"/items/0/sku" pattern must match pattern "^[A-Z]{3}-\d{4}$"
"/coords" items must NOT have more than 2 itemsEach error carries an instancePath in JSON Pointer form, so you can map it straight back to the field. A valid order (id: 42, a real email, status: "paid", SKU ABC-1234, two coordinates) returns true.
What changed from draft-07 to 2020-12?
The official 2020-12 release notes describe the changes from 2019-09, which itself changed a lot from draft-07. These are the ones that affect day-to-day schemas:
| Draft-07 | 2020-12 | Note |
|---|---|---|
definitions | $defs | Ajv2020 still resolves a $ref to #/definitions/x, since refs are plain JSON Pointers |
items: [ ... ] + additionalItems | prefixItems + items | Array-form items is now a schema error: "data/items must be object,boolean" |
dependencies | dependentRequired, dependentSchemas | Split since 2019-09 |
| None | unevaluatedProperties, unevaluatedItems | Closes objects composed with allOf, which additionalProperties cannot |
$recursiveRef (2019-09) | $dynamicRef, $dynamicAnchor | For extensible recursive schemas |
format often asserted | Split into format-annotation and format-assertion vocabularies | Do not rely on format rejecting bad data unless your validator enables it |
What are the most common JSON Schema mistakes?
Using the wrong draft without noticing
Keywords a validator does not know are ignored in lenient mode. We ran the order schema without its $schema line through Ajv in draft-07 mode. prefixItems was skipped, and draft-07 read "items": false as "no items allowed at all", so the valid order with two coordinates failed. Likewise, unevaluatedProperties: false accepted an extra property under draft-07 and rejected it under 2020-12. Same schema, different answers. Always declare $schema.
Forgetting additionalProperties
Objects are open by default. Without "additionalProperties": false, a typo like "emial" passes validation and the real field is simply missing. Add required for fields that must exist.
Expecting format to validate
In 2020-12, format is an annotation unless the format-assertion vocabulary is enabled. In Ajv2020 without ajv-formats and with strict: false, "nope" passed as an email, with only an "unknown format ignored" warning. Add ajv-formats or use pattern.
Old draft-04 habits
"exclusiveMinimum": true next to minimum is draft-04 syntax. Since draft-06 it takes a number, and Ajv2020 rejects the boolean form: "exclusiveMinimum must be number".
How do JSON Schemas work with LLM structured outputs?
Structured outputs and tool calling both take a JSON Schema, but usually only a subset. Anthropic's structured outputs documentation lists no support for recursive schemas, numeric constraints such as minimum and maximum, string-length constraints, or additionalProperties set to anything other than false. minItems works only with 0 or 1. Supported formats include date-time, email, uri and uuid.
The practical pattern: give the model a simplified schema it can follow, then validate the result against your full schema with Ajv, including the minimum and pattern rules the provider dropped. If the model output is not even parseable, see how to fix invalid JSON from LLMs. Large schemas also cost prompt tokens on every call; tool schema token overhead shows how much, and our structured outputs comparison covers provider differences.
Can I validate JSON Schema online?
Yes. The json2toon.co JSON Schema validator runs Ajv in your browser and shows each error with its line. One honest caveat: it currently runs in draft-07 mode. A schema that declares the 2020-12 $schema URL produces the "no schema with key or ref" error above. To test a 2020-12 schema there, remove the $schema line and stick to keywords both drafts share: type, required, properties, enum, const, pattern, minimum, anyOf, allOf and $ref to $defs. For prefixItems or unevaluatedProperties, use Ajv2020 locally. If your JSON will not parse at all, run it through the JSON Repair tool first.
Frequently Asked Questions
What is the current version of JSON Schema?
The current version is 2020-12, and the previous one was 2019-09, according to json-schema.org. Declare it with "$schema": "https://json-schema.org/draft/2020-12/schema". MCP tool schemas also default to 2020-12 when no $schema is present.
What changed between draft-07 and 2020-12?
The biggest practical changes: definitions became $defs, array-form items became prefixItems, items now only describes the remaining elements, dependencies split into dependentRequired and dependentSchemas, unevaluatedProperties and unevaluatedItems were added, and format is an annotation by default rather than an assertion.
Why does Ajv say no schema with key or ref for 2020-12?
The default Ajv export targets draft-07 and does not know the 2020-12 meta-schema, so it throws: no schema with key or ref "https://json-schema.org/draft/2020-12/schema". Import Ajv2020 from "ajv/dist/2020" instead, and add ajv-formats if you want format checks.
Can I validate a 2020-12 schema in the json2toon.co validator?
Partly. The browser validator runs Ajv in draft-07 mode. Remove the $schema line and avoid 2020-12-only keywords such as prefixItems and unevaluatedProperties, which draft-07 ignores. Core keywords like type, required, properties, enum, pattern, minimum and $ref to $defs behave the same.
Recommended Reading
Fix Invalid JSON From LLMs: Truncation, Commas, Quotes
Fix invalid JSON from LLMs: truncated output, trailing commas, single quotes and code fences. How to repair it, when to use structured outputs, and a free tool.
TOON Keyed Tables: Encoding Maps of Objects in Fewer Tokens
TOON keyed tables collapse objects keyed by ID or name, like feature flags or user maps, into one table. Syntax, rules and the 54.6% savings vs JSON.
How to Decode a JWT (and Why Decoding Is Not Verifying)
Decode a JWT in your browser: split the header, claims and signature, read exp and aud, and learn why decoding a token is not the same as verifying it.