1
- # JSON Schema: A Media Type for Describing JSON Documents
1
+ # JSON Schema: A Language for Validating and Annotating JSON
2
2
3
3
## Abstract
4
4
5
- JSON Schema defines the media type ` application/schema+json ` , a JSON-based
6
- format for describing the structure of JSON data. JSON Schema asserts what a
7
- JSON document must look like, ways to extract information from it , and how to
8
- interact with it. The ` application/schema-instance+json ` media type provides
9
- additional feature-rich integration with ` application/schema+json ` beyond what
10
- can be offered for ` application/json ` documents .
5
+ This document specifies JSON Schema , a domain-specific, declarative language for
6
+ validating and annotating JSON documents. It defines a vocabulary for creating
7
+ schemas that describe the structure, constraints , and meta-data associated with
8
+ a JSON document. JSON Schema provides a standardized way to define the contracts
9
+ for JSON-based APIs and data formats, facilitating automated validation,
10
+ documentation, and other related tooling .
11
11
12
12
## Note to Readers
13
13
@@ -23,17 +23,54 @@ the homepage, or email the document editors.
23
23
24
24
## Introduction
25
25
26
- JSON Schema is a JSON media type for defining the structure of JSON data. JSON
27
- Schema is intended to define validation, documentation, hyperlink navigation,
28
- and interaction control of JSON data.
26
+ JSON is a widely used, language-independent data format. While it is excellent
27
+ for data exchange, JSON itself lacks a native mechanism for formally describing
28
+ its structure and constraints. This absence can lead to ambiguity and errors in
29
+ data interchange, particularly in contexts such as API development,
30
+ configuration files, and data storage.
31
+
32
+ This document defines JSON Schema, a domain-specific, declarative language for
33
+ validating and annotating JSON documents. JSON Schema can be represented as a
34
+ JSON document itself, which makes it easily portable and machine-readable.
35
+
36
+ JSON Schema draws inspiration from the architecture of the World Wide Web,
37
+ including concepts such as URIs for identifying and linking schemas. While it
38
+ can be applied in many domains, those qualities make it especially well-suited
39
+ for describing and validating data exchanged in web APIs.
40
+
41
+ A JSON Schema serves as a contract for data. It is primarily designed for two
42
+ purposes: validation and annotation. Validation ensures that a JSON instance
43
+ conforms to a specific structure and set of constraints. Annotation attaches
44
+ metadata to values in a JSON document, which can be used by applications in a
45
+ variety of ways.
46
+
47
+ JSON Schema can also be used for a variety of other use cases, including
48
+ documentation generation, HTML form builders, and type code generation. Although
49
+ it is not specifically designed for those tasks, JSON Schema can be extended to
50
+ fill any gaps required to support these secondary uses.
51
+
52
+ The JSON Schema specification is defined in a series of documents, each
53
+ addressing a different aspect of the language. This document, the Core
54
+ specification, defines the fundamental keywords and concepts. It is intended to
55
+ be implemented as the foundational layer upon which other related specifications
56
+ can build to define additional vocabularies or features for specific use cases.
29
57
30
- This specification defines JSON Schema core terminology and mechanisms,
31
- including pointing to another JSON Schema by reference, dereferencing a JSON
32
- Schema reference, specifying the dialect being used, and defining terms.
58
+ This document defines a set of core keywords that MUST be supported by any
59
+ implementation, and cannot be disabled. These keywords are each prefixed with a
60
+ "$" character to emphasize their required nature. These keywords are considered
61
+ essential to the functioning of JSON Schema.
62
+
63
+ Additionally, this document defines a RECOMMENDED set of keywords for
64
+ conditionally applying subschemas and for applying subschemas to the contents of
65
+ objects and arrays. These keywords, or a set very much like them, are necessary
66
+ to write schemas for non-trivial JSON instances, whether those schemas are
67
+ intended for validation, annotation, or both. For maximum interoperability, this
68
+ additional set is included in this document and its use is strongly encouraged.
33
69
34
- Other specifications define keywords that perform assertions about validation,
35
- linking, annotation, navigation, interaction, as well as other related concepts
36
- such as output formats.
70
+ This document obsoletes the previous "draft" releases for JSON Schema and
71
+ provides the basis for a stable, standardized version. Implementations MAY
72
+ continue to support "draft" releases in order to facilitate the transition,
73
+ typically by inspecting the value of the ` $schema ` keyword.
37
74
38
75
## Conventions and Terminology
39
76
@@ -47,44 +84,22 @@ document are to be interpreted as defined in [RFC 8259][rfc8259].
47
84
48
85
## Overview
49
86
50
- This document proposes a new media type ` application/schema+json ` to identify a
51
- JSON Schema for describing JSON data. It also proposes a further optional media
52
- type, ` application/schema-instance+json ` , to provide additional integration
53
- features. JSON Schemas are themselves JSON documents. This, and related
54
- specifications, define keywords allowing authors to describe JSON data in
55
- several ways.
56
-
57
- JSON Schema uses keywords to assert constraints on JSON instances or annotate
58
- those instances with additional information. Additional keywords are used to
59
- apply assertions and annotations to more complex JSON data structures, or based
60
- on some sort of condition.
61
-
62
- To facilitate re-use, keywords can be organized into vocabularies. A vocabulary
63
- consists of a list of keywords, together with their syntax and semantics. A
64
- dialect is defined as a set of vocabularies and their required support
65
- identified in a meta-schema.
66
-
67
- JSON Schema can be extended either by defining additional vocabularies, or less
68
- formally by defining additional keywords outside of any vocabulary. Unrecognized
69
- individual keywords are not supported.
70
-
71
- This document defines a set of core keywords that MUST be supported by any
72
- implementation, and cannot be disabled. These keywords are each prefixed with a
73
- "$" character to emphasize their required nature. These keywords are essential
74
- to the functioning of the ` application/schema+json ` media type.
75
-
76
- Additionally, this document defines a RECOMMENDED set of keywords for
77
- applying subschemas conditionally, and for applying subschemas to the contents
78
- of objects and arrays. These keywords, or a set very much like them, are
79
- required to write schemas for non-trivial JSON instances, whether those schemas
80
- are intended for assertion validation, annotation, or both. While not part of
81
- the required core set, for maximum interoperability this additional
82
- set is included in this document and its use is strongly encouraged.
83
-
84
- Further keywords for purposes such as structural validation or hypermedia
85
- annotation are defined in other documents. These other documents each define a
86
- dialect collecting the standard sets of keywords needed to write schemas for
87
- that document's purpose.
87
+ A JSON Schema represents a set of constraints and annotations that are applied
88
+ to a JSON value. These constraints and annotations are declared using
89
+ "keywords". A JSON value is considered valid against a schema if, and only if,
90
+ it satisfies the constraint defined by every keyword in that schema.
91
+
92
+ Schema evaluation is a recursive process. Some keywords contain one or more
93
+ subschemas. These keywords can be used to create complex constraints or to
94
+ describe compound values like arrays and objects. For example, to describe a
95
+ JSON object, a schema can use the ` type ` keyword to declare that the value MUST
96
+ be an object, and the ` properties ` keyword to apply separate schemas to each of
97
+ the object's properties. This allows for the evaluation of a complex JSON
98
+ document using a uniform recursive algorithm.
99
+
100
+ JSON Schema defines an official collection of keywords (called a dialect), but
101
+ it also includes a flexible extension model that allows for third-parties to
102
+ define their own dialects of JSON Schema.
88
103
89
104
## Definitions
90
105
0 commit comments