Author, refactor, and maintain JSON Schema for reuse, composition, and long-term stability. Use when asked to create schemas, reduce duplication, compose schemas with $ref/allOf/oneOf/if-then-else, review schema quality, or migrate legacy draft-04+ schemas. Prefer draft-2020-12 for new authoring; treat draft-04/draft-06 as migration-only.
Create and evolve JSON Schema contracts that stay reusable, readable, and safe to change.
$ref, allOf, oneOf, or conditionals$defs + $ref, not copy-paste$schema, stable $id, title, and description.type, properties, required, and object openness policy.$defs (or definitions when staying on draft-07).allOf for orthogonal layering, oneOf for exclusive variants, and if/then/else for conditional rules.Draft-2020-12 baseline:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/schemas/entity.json",
"type": "object",
"properties": {},
"required": [],
"unevaluatedProperties": false,
"$defs": {}
}
Draft-07 baseline:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://example.com/schemas/entity.json",
"type": "object",
"properties": {},
"required": [],
"additionalProperties": false,
"definitions": {}
}
id -> $id; definitions -> $defs; dependencies -> dependentRequired or dependentSchemas; re-check exclusiveMinimum/exclusiveMaximum behavior.$id$ref, not duplicate subschemasajv validate -s schemas/example.json -d fixtures/valid/*.json
ajv validate -s schemas/example.json -d fixtures/invalid/*.json && exit 1 || true