JSON 14 ๐ JSON Schema Specifications โ Draft 7 vs Draft 2020-12
The JSON Schema specification has gone through several drafts, and the two that matter most in current practice are Draft 7 and Draft 2020-12. Draft 7 was published in March 2018 and was a relatively minor update to Draft 6, fully backwards-compatible in terms of the validation keywords and the outcomes . Draft 2020-12 is the current version, and it is a comprehensive update that introduced the vocabulary system, the redesigned array keywords, the dynamic references, and the unevaluatedProperties/unevaluatedItems keywords . The choice between the two is not a choice between “old” and “new” in the abstract. It is a choice about which features the project needs and which libraries support them.
The official JSON Schema website states the current version is 2020-12, and the previous version was 2019-09 . Draft 7 is older, but it is still widely supported and widely used. A migration from Draft 7 to 2020-12 is not a drop-in change. The keywords were renamed, the array behaviour was redesigned, and the format keyword became annotation-only by default . A project that does not need the 2020-12 features can stay on Draft 7, and a project that needs the new keywords must migrate.
Key point: Draft 7 is a stable, widely supported specification that is fully backwards-compatible with Draft 6. Draft 2020-12 is the current version, with the prefixItems/items split, the dependentSchemas/dependentRequired split, the $defs container, the dynamic references, and the unevaluatedProperties/unevaluatedItems keywords. The format keyword is annotation-only in 2020-12 unless the vocabulary opts into the assertion behaviour.
Why the two drafts coexist
The compatibility problem. Draft 7 is fully backwards-compatible with Draft 6 in terms of the validation keywords and the outcomes . A project that is on Draft 6 can move to Draft 7 without the breaking changes, and a project that is on Draft 7 has no forcing function to move to 2020-12 unless it needs the new features. The compatibility is the reason Draft 7 remains in use, and the stability is the reason the libraries continue to support it.
The migration cost problem. A migration from Draft 7 to 2020-12 is not a version bump. The keywords were renamed: the items became prefixItems for the tuple validation and items for the rest, the dependencies became dependentSchemas and dependentRequired, and the definitions became $defs . A real-world migration report counted 464 breaking edits across 116 schemas, with “zero functional benefit” for that specific project because none of its schemas used the features that require 2020-12 . The cost is the mechanism that keeps the projects on Draft 7.
The feature problem. Draft 2020-12 introduced the features that Draft 7 does not have. The unevaluatedProperties and the unevaluatedItems are the keywords that apply the strictness after all the subschemas have evaluated, and they are the fix for the allOf with the additionalProperties trap . The $dynamicRef and the $dynamicAnchor replace the older $recursiveRef and $recursiveAnchor, and they are the mechanism for the extensible recursive schemas . The features are the reason a project migrates, and the absence of the need is the reason a project does not.
The format problem. In Draft 7, the format keyword is an assertion by default: an invalid email fails the validation. In 2019-09 and 2020-12, the format keyword is annotation-only by default, and the format validators are not enforced unless the schema opts into the assertion vocabulary . The change is the mechanism that separates the annotation from the assertion, and it is the breaking change that a project relying on the format validation must handle.
The vocabulary problem. Draft 2020-12 introduced the $vocabulary keyword, and the specification is split into the Core and the Validation vocabularies . The $vocabulary is the mechanism that declares which vocabularies the schema uses, and the split is the reason the 2020-12 meta-schema is composed of the multiple vocabulary files. Draft 7 does not have the vocabulary system, and the single specification document is the complete definition.
a. The keyword differences and the array redesign
The array keywords were redesigned in 2020-12. In Draft 7, the items keyword is either a single schema that applies to every element, or an array of schemas that applies to the elements at the corresponding positions, with the additionalItems keyword controlling the rest . In 2020-12, the tuple validation is the prefixItems keyword, and the items keyword applies to the elements after the prefix .
// Draft 7 โ the tuple with the additional items
{
"type": "array",
"items": [
{ "type": "string" },
{ "type": "number" }
],
"additionalItems": false
}
// Draft 2020-12 โ the tuple with the prefix items
{
"type": "array",
"prefixItems": [
{ "type": "string" },
{ "type": "number" }
],
"items": false
}
The Draft 7 items array and the additionalItems are the equivalent of the 2020-12 prefixItems and the items. The items in 2020-12 is the schema for the elements after the prefix, and the false value is the mechanism that disallows the additional elements . The Ajv documentation states the additionalItems is not supported in 2020-12, and the equivalent is the prefixItems with the new items .
The dependencies keyword was split in 2020-12. In Draft 7, the dependencies is either a schema dependency (the value is a schema that applies when the property is present) or a property dependency (the value is an array of the property names that are required when the property is present) . In 2020-12, the schema dependency is the dependentSchemas, and the property dependency is the dependentRequired .
// Draft 7 โ the dependencies
{
"dependencies": {
"creditCard": ["billingAddress"],
"country": { "properties": { "postalCode": { "pattern": "^[0-9]{5}$" } } }
}
}
// Draft 2020-12 โ the split keywords
{
"dependentRequired": {
"creditCard": ["billingAddress"]
},
"dependentSchemas": {
"country": { "properties": { "postalCode": { "pattern": "^[0-9]{5}$" } } }
}
}
The split is the mechanism that separates the two dependency types, and the dependentRequired is the presence-based condition while the dependentSchemas is the schema-based condition .
The definitions container was renamed to $defs in 2019-09. The $defs is the standard location for the reusable subschemas, and the definitions is not recognized by the 2020-12 meta-schema .
// Draft 7 โ the definitions
{
"definitions": {
"address": { "type": "object" }
}
}
// Draft 2020-12 โ the $defs
{
"$defs": {
"address": { "type": "object" }
}
}
The rename is the mechanism that avoids the confusion with the definitions keyword in the older drafts, and the $defs is the only recognized container in 2020-12.
b. The new keywords and the format change
The unevaluatedProperties and the unevaluatedItems are the new keywords in 2019-09 and 2020-12. The unevaluatedProperties is the mechanism that applies the strictness after all the subschemas have evaluated, and it is the fix for the allOf with the additionalProperties trap . The unevaluatedItems is the equivalent for the arrays, and the 2020-12 specifies how the contains keyword affects it .
// Draft 2020-12 โ the unevaluatedProperties
{
"allOf": [
{ "properties": { "a": { "type": "string" } } }
],
"unevaluatedProperties": false
}
The unevaluatedProperties sees the a that the allOf evaluated, and the false rejects the properties that no subschema evaluated . The additionalProperties inside the allOf would not see the sibling properties, and the unevaluatedProperties is the mechanism that fixes the limitation.
The dynamic references are the second new feature. The $dynamicRef and the $dynamicAnchor replace the $recursiveRef and the $recursiveAnchor from 2019-09, and they are the mechanism for the extensible recursive schemas . The dynamic reference is the more general mechanism, and the 2020-12 release notes describe the change .
The format keyword changed the behaviour. In Draft 7, the format is an assertion by default. In 2019-09 and 2020-12, the format is annotation-only by default, and the format validators are not enforced unless the schema opts into the assertion vocabulary . The migration guide states the change explicitly: “In these drafts, the JSON Schema specification treats format as annotation-only โ unknown formats no longer produce UNKNOWN_FORMAT errors, and format validators are not enforced unless explicitly opted into” . The change is the mechanism that separates the annotation from the assertion, and the opt-in is the mechanism that restores the Draft 7 behaviour.
The contains and the unevaluatedItems interaction is the 2020-12 specification. In 2019-09, it was not specified how the contains affects the unevaluatedItems. The 2020-12 specifies that any item that passes the contains validation is considered “evaluated”, and the unevaluatedItems does not apply to it . The change is the mechanism that makes the contains composable with the unevaluatedItems, and the release notes show the example and the workaround .
Complete Example Session
// ============================================
// PART 1: THE DRAFT 7 SCHEMA
// ============================================
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": { "type": "string" }
},
"required": ["name"],
"definitions": {
"address": { "type": "object" }
}
}
// The draft-07 schema uses the definitions container.
// ============================================
// PART 2: THE 2020-12 SCHEMA
// ============================================
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" }
},
"required": ["name"],
"$defs": {
"address": { "type": "object" }
}
}
// The 2020-12 schema uses the $defs container.
// ============================================
// PART 3: THE TUPLE DIFFERENCE
// ============================================
// The draft-07 tuple
{
"type": "array",
"items": [{ "type": "string" }, { "type": "number" }],
"additionalItems": false
}
// The 2020-12 tuple
{
"type": "array",
"prefixItems": [{ "type": "string" }, { "type": "number" }],
"items": false
}
// The items became the prefixItems, and the additionalItems became the items.
// ============================================
// PART 4: THE DEPENDENCY DIFFERENCE
// ============================================
// The draft-07 dependencies
{
"dependencies": {
"creditCard": ["billingAddress"]
}
}
// The 2020-12 dependentRequired
{
"dependentRequired": {
"creditCard": ["billingAddress"]
}
}
// The dependencies split into the dependentRequired and the dependentSchemas.
// ============================================
// PART 5: THE UNEVALUATED PROPERTIES
// ============================================
{
"allOf": [
{ "properties": { "a": { "type": "string" } } }
],
"unevaluatedProperties": false
}
// The unevaluatedProperties is the 2019-09 and the 2020-12 keyword.
// It sees the properties evaluated by the allOf.
// ============================================
// PART 6: THE DYNAMIC REFERENCE
// ============================================
{
"$dynamicRef": "#item"
}
// The $dynamicRef is the 2020-12 keyword.
// It replaces the $recursiveRef from the 2019-09.
// ============================================
// PART 7: THE FORMAT CHANGE
// ============================================
{
"type": "string",
"format": "email"
}
// The draft-07 asserts the email format.
// The 2020-12 treats the format as an annotation by default.
// ============================================
// PART 8: THE FORMAT ASSERTION OPT-IN
// ============================================
// The 2020-12 schema with the format assertion vocabulary.
{
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/format-assertion": true
}
}
// The vocabulary opts into the format assertion.
// ============================================
// PART 9: THE MIGRATION COST
// ============================================
// The 116 schemas with the 4 changes each.
// The 464 breaking edits.
// The zero functional benefit for the project that does not use the new features.
// ============================================
// PART 10: THE CHECKLIST
// ============================================
// [ ] The schema declares the $schema version.
// [ ] The definitions are in the $defs for the 2020-12.
// [ ] The tuple uses the prefixItems and the items for the 2020-12.
// [ ] The dependencies use the dependentRequired and the dependentSchemas.
// [ ] The unevaluatedProperties is used for the strict objects.
// [ ] The format assertion is opted in for the 2020-12.
The ten parts covered the Draft 7 schema, the 2020-12 schema, the tuple difference, the dependency difference, the unevaluated properties, the dynamic reference, the format change, the format assertion opt-in, the migration cost, and the checklist. The through-line is that the 2020-12 is the current version with the new features, and the Draft 7 is the stable version that the projects stay on when they do not need the new features.
Quick Reference
The keyword differences
| Draft 7 | Draft 2020-12 | Notes |
|---|---|---|
definitions | $defs | The container rename |
items (array) | prefixItems | The tuple validation |
additionalItems | items | The additional elements |
dependencies (property) | dependentRequired | The presence dependency |
dependencies (schema) | dependentSchemas | The schema dependency |
| โ | unevaluatedProperties | The strict objects |
| โ | unevaluatedItems | The strict arrays |
$recursiveRef / $recursiveAnchor | $dynamicRef / $dynamicAnchor | The recursive schemas |
format (assertion) | format (annotation) | The assertion opt-in |
The format change
| Draft | Format behaviour |
|---|---|
| Draft 7 | Assertion by default |
| 2019-09 | Annotation-only by default |
| 2020-12 | Annotation-only by default |
The migration cost
| Aspect | Detail |
|---|---|
| The breaking changes | The keyword renames |
| The real-world count | The 464 edits across the 116 schemas |
| The functional benefit | None if the new features are not used |
Best Practices
โ Do This:
// Declare the $schema version
{ "$schema": "https://json-schema.org/draft/2020-12/schema" } // โ
// Use the $defs for the reusable subschemas
{ "$defs": { "address": { "type": "object" } } } // โ
// Use the unevaluatedProperties for the strict objects
{ "allOf": [{ "properties": { "a": {} } }], "unevaluatedProperties": false } // โ
โ Don’t Do This:
// Use the definitions in the 2020-12
{ "definitions": {} } // the not recognized container // โ
// Assume the format is an assertion in the 2020-12
{ "format": "email" } // the annotation only by default // โ
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| The schema is ignored | The $schema is missing | Add the $schema |
| The tuple validation fails | The items array is used in the 2020-12 | Use the prefixItems |
| The format is not validated | The format is annotation-only in the 2020-12 | Opt into the format assertion |
The additionalProperties rejects the sibling properties | The subschemas are independent | Use the unevaluatedProperties |
Real-World Examples
1. The Draft 7 schema
{ "$schema": "http://json-schema.org/draft-07/schema#" }
2. The 2020-12 schema
{ "$schema": "https://json-schema.org/draft/2020-12/schema" }
3. The $defs
{ "$defs": { "address": { "type": "object" } } }
4. The prefixItems
{ "prefixItems": [{ "type": "string" }], "items": false }
5. The dependentRequired
{ "dependentRequired": { "creditCard": ["billingAddress"] } }
6. The dependentSchemas
{ "dependentSchemas": { "country": { "properties": {} } } }
7. The unevaluatedProperties
{ "allOf": [{ "properties": { "a": {} } }], "unevaluatedProperties": false }
8. The dynamicRef
{ "$dynamicRef": "#item" }
9. The format assertion
{ "$vocabulary": { "https://json-schema.org/draft/2020-12/vocab/format-assertion": true } }
10. The migration
// The definitions โ the $defs
// The items โ the prefixItems
// The dependencies โ the dependentRequired
Visual
The Array Redesign
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ THE ARRAY REDESIGN โ
โ โ
โ Draft 7: โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ items: [A, B] โ The tuple โ
โ โ additionalItems: โ The additional elements โ
โ โ false โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ 2020-12: โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ prefixItems: [A, B] โ The tuple โ
โ โ items: false โ The additional elements โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The Format Change
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ THE FORMAT CHANGE โ
โ โ
โ Draft 7: โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ format: "email" โ The assertion โ
โ โ โ The invalid email fails โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ 2020-12: โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ format: "email" โ The annotation โ
โ โ โ The invalid email passes โ
โ โ โ unless the assertion is opted in โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The Migration Cost
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ THE MIGRATION COST โ
โ โ
โ The 116 schemas โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ The 4 changes each โ The keyword renames โ
โ โ The 464 edits โ โ
โ โโโโโโโโโโโโฌโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ The zero functional โ If the new features are not used โ
โ โ benefit โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Item | Value |
|---|---|
| The current version | 2020-12 |
| The previous version | 2019-09 |
| The Draft 7 compatibility | The fully backwards-compatible with the Draft 6 |
| The keyword renames | definitions โ $defs, items โ prefixItems, dependencies โ dependentRequired/dependentSchemas |
| The new keywords | unevaluatedProperties, unevaluatedItems, $dynamicRef, $dynamicAnchor |
| The format change | The assertion โ the annotation in 2019-09 and 2020-12 |
| The migration cost | The 464 edits across the 116 schemas in the real-world report |
Key takeaways:
- Draft 7 is the stable, widely supported version. It is fully backwards-compatible with Draft 6, and it is the version that the libraries continue to support. A project that does not need the 2020-12 features can stay on Draft 7 without the migration cost .
- Draft 2020-12 is the current version with the new features. The
unevaluatedProperties, theunevaluatedItems, the$dynamicRef, and the$dynamicAnchorare the features that Draft 7 does not have, and the keyword renames are the breaking changes that the migration must handle . - The array and the dependency keywords were redesigned. The
itemsbecame theprefixItems, theadditionalItemsbecame theitems, and thedependenciesbecame thedependentRequiredand thedependentSchemas. The migration is not a version bump; it is the keyword rewrite. - The
formatkeyword is annotation-only in 2020-12. The Draft 7 asserts the format by default, and the 2020-12 requires the explicit vocabulary opt-in for the assertion. The change is the mechanism that separates the annotation from the assertion . - The migration cost is the reason the projects stay on Draft 7. The real-world report counted 464 edits across the 116 schemas with the zero functional benefit for the project that does not use the new features . The cost is the mechanism that keeps the Draft 7 in use, and the need for the new features is the reason to migrate.
Remember: The JSON Schema has the two active drafts: the Draft 7 and the 2020-12. The Draft 7 is the stable, backwards-compatible version that the projects stay on when they do not need the new features. The 2020-12 is the current version with the unevaluatedProperties, the $dynamicRef, and the redesigned array and dependency keywords. The migration is the keyword rewrite, and the cost is the reason the Draft 7 remains in use.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!