Introduction
JSON Schema can be used to require that a given JSON document (an instance) satisfies a certain number of criteria. These criteria are asserted by using keywords described in this specification. In addition, a set of keywords is also defined to assist in interactive user interface instance generation.How Validation Works
JSON Schema validation asserts constraints on the structure of instance data. An instance location that satisfies all asserted constraints is then annotated with any keywords that contain non-assertion information, such as descriptive metadata and usage hints.If all locations within the instance satisfy all asserted constraints, then the instance is said to be valid against the schema.
Keyword Behaviors
The keywords defined in the validation specification exhibit one or more behaviors:- Assertion keywords: Produce validation results (true or false)
- Annotation keywords: Provide metadata without affecting validation
- Hybrid keywords: Can function as both assertions and annotations
Validation Process
For the purposes of validation, an instance “validating against a keyword” means that:- The keyword evaluates the instance against its constraint
- If the instance satisfies the constraint, the keyword produces an assertion result of
true - If the instance does not satisfy the constraint, the keyword produces an assertion result of
false
Validation Keyword Categories
This specification defines several categories of validation keywords:Structural Validation
Keywords for validating types, numbers, strings, arrays, and objects
Format Validation
Semantic validation for common data formats like dates, emails, and URIs
Content Validation
Keywords for string-encoded data like base64 or embedded JSON
Annotations
Meta-data keywords for documentation and UI generation
Interoperability Considerations
String Instances
The nul character (\u0000) is valid in a JSON string. An instance to validate may contain a string value with this character, regardless of the ability of the underlying programming language to deal with such data.
Numeric Instances
The JSON specification allows numbers with arbitrary precision, and JSON Schema does not add any such bounds. This means that numeric instances processed by JSON Schema can be arbitrarily large and/or have an arbitrarily long decimal part, regardless of the ability of the underlying programming language to deal with such data.Regular Expressions
Keywords that use regular expressions, or constrain the instance value to be a regular expression, are subject to interoperability considerations. Different implementations may support different regular expression dialects, which can affect validation outcomes.Meta-Schema
The current IRI for the default JSON Schema dialect meta-schema is:https://json-schema.org/v1 is also recognized to represent the latest release within the indicated version.
Implementations MUST NOT assume that a document is provided at the meta-schema URL. Rather than performing a network request, implementations SHOULD include a copy of the meta-schema.
Terminology
Container instance: Refers to both array and object instances. Children instances: Refers to array elements or object member values. Unique elements: Elements in an array value are said to be unique if no two elements of this array are equal according to the JSON Schema Core specification.Next Steps
Explore the specific validation keyword categories:- Structural Validation Keywords - Type checking and structural constraints
- Format Validation - Semantic format validation
- Content Validation - String-encoded data handling
- Annotation Keywords - Meta-data and documentation