JSON Schema Demystified: Dialects, Vocabularies and Metaschemas
13 days ago
- #JSON Schema
- #Metaschema
- #Data Validation
- JSON Schema is used to describe the shape and constraints of JSON data.
- A schema is a JSON document that defines rules for other JSON documents.
- Metaschemas are schemas that describe the structure of other schemas, ensuring they are well-formed.
- Dialects refer to specific versions or flavors of JSON Schema, each defined by a unique metaschema.
- Vocabularies are modular collections of keywords introduced in Draft 2019-09, allowing for extensibility and customization.
- Keywords are the properties used in schemas (like 'type', 'properties') defined by vocabularies.
- JSON Schema can be extended with custom keywords for domain-specific validation, similar to how OpenAPI extends JSON Schema for API descriptions.
- Annotations (like 'title', 'description') provide metadata without affecting validation, while assertions (like 'minimum', 'required') enforce validation rules.
- Practical advice includes always specifying the '$schema' keyword, using the latest stable dialect, and breaking complex schemas into reusable parts with '$defs'.