You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: jsonschema-use-cases.xml
+79-18
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@
32
32
33
33
<abstract>
34
34
<t>
35
-
To foster development of JSON Schema, this document contains a list of use cases and requirements that may be used to inform its development and evolution. All examples should be realistic examples of how people may use JSON Schema.
35
+
To foster development of JSON Schema, this document contains a list of use cases and requirements that may be used to inform its development and evolution.
36
36
</t>
37
37
</abstract>
38
38
<notetitle="Note to Readers">
@@ -64,24 +64,76 @@
64
64
65
65
<sectiontitle="Conventions and Terminology">
66
66
<t>
67
-
Use Cases describe the system's behavior under various conditions, cataloging who does what with the system, for what purpose, but without concern for system design or implementation.
67
+
Objectives specify the class of problems that are in the scope of the specification.
68
68
</t>
69
69
70
70
<t>
71
-
Requirements list functional and non-functional or quality requirements, and the use cases they may be derived from/related to.
71
+
Use Cases catalog a variety of personal objectives that users may have, due to various objectives and constraints, that the specification shall address, but without concern for a specific design or implementation. Use cases guide the minimum functionality that the specification must be capable of.
72
+
</t>
73
+
74
+
<t>
75
+
Requirements list functional, non-functional, and quality requirements, the use cases they may be derived from/related to, and reference how each use case is implemented.
76
+
</t>
77
+
78
+
<t>
79
+
Not all implementations are required to implement all requirements. Only requirements that that are required for interoperability are part of the core semantics. Other requirements, where applications can gracefully degrade in the absence of support by an implementation, may be written as extensions.
72
80
</t>
73
81
</section>
74
-
expressed as a context-free grammar that follows JSON
82
+
83
+
<sectiontitle="Objectives">
84
+
<t>
85
+
JSON Schema shall be built to support two objectives, including unstandardized uses, not described by any use case, but that fall within an objective.
86
+
</t>
87
+
88
+
<sectiontitle="Validation">
89
+
<t>
90
+
The first objective of JSON Schema is to describe sets of JSON documents; specifically, to notate a language of JSON documents using a machine-readable, set-builder notation.
91
+
This covers the key use case of validating input using a validator, as well as numerous other tools that depend on describing to each other which kinds of JSON documents are and are not acceptable.
92
+
</t>
93
+
</section>
94
+
95
+
<sectiontitle="Annotation">
96
+
<t>
97
+
The second objective of JSON Schema is to map an input JSON document to an arbitrary output described by the user.
98
+
Annotations may be combined with validation (in the same schema) to specify the domain of inputs for which an output is defined.
99
+
This covers the key use case of documenting the meaning of properties and values in JSON documents, and other uses where the input document is being interpreted in some fashion.
100
+
</t>
101
+
</section>
102
+
103
+
<sectiontitle="Internet">
104
+
<t>
105
+
JSON is a technology standardized as a part of a larger ecosystem of Internet technology, and likewise, JSON Schema may also specify how it is used in this ecosystem, for example, use in HTTP, or the meaning of media type parameters.
106
+
</t>
107
+
</section>
108
+
109
+
<sectiontitle="Out of scope">
110
+
<t>
111
+
Use cases or requirements that do not advance these objectives are likely out of scope, and better suited in separate work that references JSON Schema.
112
+
</t>
113
+
<t>
114
+
For example, a method of describing an API interface would exceed the scope of JSON Schema, although JSON Schema may be used as a part of such a description, in the cases where describing JSON documents is necessary.
Structural validation refers to define the "structure" or pattern that a JSON document is supposed to follow, such as which properties must exist, what types of values are expected where, and what they must look like. More specifically, structural validation is any validation that can be expressed as a context-free grammar that follows JSON semantics, so that different forms which are equal according to JSON will be guaranteed to have the same validation result.
127
+
Structural validation refers to the "structure" that a JSON document is supposed to follow, such as which properties must exist, what types of values are expected where, and what they must look like. Constraints cannot read values elsewhere in the document (e.g. comparing two values for equality), though constraints may be added depending on "where" the value is found (e.g. a specific property or array item must have a number as its value).
79
128
</t>
80
129
<t>
81
-
Validators that support structural validation can entirely replace generic grammar languages such as <xreftarget="RFC5234">ABNF</xref> and in addition, guarantee compliance with JSON semantics. Schemas whose validation is limited to structural validation can be implemented as a deterministic pushdown automata, and guarantee a result in proportional time without error.
130
+
More specifically, structural validation is any validation that can be expressed as a context-free grammar that follows JSON semantics, so that different forms which are equal according to JSON will be guaranteed to have the same validation result.
82
131
</t>
83
132
<t>
84
-
The following features of JSON are part of structural validation:
133
+
Validators that support structural validation can entirely replace generic grammar languages such as <xreftarget="RFC5234">ABNF</xref>, and will guarantee compliance with JSON semantics. Likewise, schemas whose validation rules are limited to structural validation can be executed using a deterministic pushdown automata, guaranteeing a result in proportional time without error.
134
+
</t>
135
+
<t>
136
+
The following features of JSON are structural validation:
85
137
</t>
86
138
<list>
87
139
<t>JSON primitive type (string, object, etc)</t>
@@ -90,7 +142,7 @@ expressed as a context-free grammar that follows JSON
90
142
<t>Literal/constant values or alternate/enumerated values</t>
91
143
<t>Pattern matching strings by a regular expression (including object keys)</t>
<t>Descent into object properties and array items</t>
145
+
<t>Descent into object properties and array items (recursively)</t>
94
146
</list>
95
147
<t>
96
148
Multiple forms that are value-equal according to JSON are not distinguishable under this use-case. This includes the ordering of properties in an object, character escapes in strings, and whitespace.
@@ -116,19 +168,19 @@ expressed as a context-free grammar that follows JSON
116
168
117
169
<sectiontitle="Domain-specific language">
118
170
<t>
119
-
Application authors may use an entirely self-contained schema inside an application that consumes JSON. By using a declarative language, the application requirements can be better optimized by the application.
171
+
Application authors may use an entirely self-contained schema inside an application that consumes JSON. By using a declarative language, the application requirements can be optimized better than a human could do.
120
172
</t>
121
173
<t>
122
-
Application authors may define custom hooks and processing for the JSON (without need for standardizing the customization).
174
+
Application authors may use a schema to define custom hooks and processing for the JSON (without need for standardizing the customization).
123
175
</t>
124
176
<t>
125
-
The only interoperability consideration here is that updates to the validator library must not change the set of valid JSON documents, unless the developer specifically opts into such a breaking change (e.g. by upgrading the library to a new major version number).
177
+
The only interoperability consideration here is that updates to the validator library must not change the validation result of any JSON documents, unless the developer specifically opts into such a breaking change (e.g. by upgrading the library to a new major version number).
126
178
</t>
127
179
</section>
128
180
129
181
<sectiontitle="A common vocabulary">
130
182
<t>
131
-
A team of developers write two similar applications, for different platforms, in different languages. The application downloads and reads JSON documents. They want to make sure that both applications accept or reject JSON with identical behavior, so they write a single JSON Schema and deploy it to both applications.
183
+
A development team maintains two similar applications, but for different platforms, in different languages. The application downloads and reads from a common repository of JSON documents. They want to make sure that both applications accept or reject JSON with identical behavior, so they write a single JSON Schema and deploy it to both applications.
132
184
</t>
133
185
<t>
134
186
The only interoperability consideration here is that the two applications, given the same schema, must both be reasonably expected to support the same behavior and operate in the same manner.
@@ -140,7 +192,10 @@ expressed as a context-free grammar that follows JSON
140
192
When a server declares constraints that a submission must meet, there is a need for the user interface to receive these constraints to provide model-driven validation of permissible values, making the form more accessible to the user.
141
193
</t>
142
194
<t>
143
-
If the schema is ambiguous in any way, or is up to the discretion of the customer's user-agent, some customers may have a difficult time submitting a correct request.
195
+
For example, if a value is specified to be a date, the form field where the value is specified can provide immediate feedback if an invalid date is entered, and even offer a date picker to help the user input a correct value.
196
+
</t>
197
+
<t>
198
+
Weak interoperability requirements can hamper the user experience within this use case. If the schema is ambiguous in any way, or is up to the discretion of the customer's user-agent, some customers may have a difficult time submitting a correct request.
144
199
</t>
145
200
</section>
146
201
@@ -152,7 +207,7 @@ expressed as a context-free grammar that follows JSON
152
207
153
208
<sectiontitle="Embedded database constraints">
154
209
<t>
155
-
A database that uses JSON may need a way to declare, enforce, or guarantee certain constraints on the JSON document being stored. The database may use JSON Schema as a way to annotate certain fields as having a special meaning for uniqueness or indexing purposes.
210
+
A database that uses JSON may need a way to declare, enforce, or guarantee certain constraints on the JSON document being stored. The database may also use JSON Schema as a way to annotate certain fields as having a special meaning for uniqueness or indexing purposes.
156
211
</t>
157
212
</section>
158
213
@@ -163,7 +218,7 @@ expressed as a context-free grammar that follows JSON
163
218
<liststyle="symbols">
164
219
<t>Many JSON parsers cast the arbitrary-precision decimal numbers to an IEEE floating point, validating the number after it has lost some precision, because this form is read by the application.</t>
165
220
<t>Some programming languages cannot distinguish between an ordered array of values and a key-value map; or an empty array is identical to an empty object.</t>
166
-
<t>Other validators may have a limited amount of memory and cannot support assertions more complicated than a deterministic context-free grammar in the Chomsky hierarchy (i.e. validation not describable by a deterministic pushdown automata).</t>
221
+
<t>Other validators may have a limited amount of memory and cannot support assertions more complicated than a deterministic context-free grammar.</t>
167
222
</list>
168
223
<t>
169
224
Users of these validators need a way to determine if the missing functionality is essential to correct understanding, and if not, get a validation result that would be correct but-for the unimplemented functionality.
@@ -187,6 +242,12 @@ expressed as a context-free grammar that follows JSON
187
242
</t>
188
243
</section>
189
244
245
+
<sectiontitle="Results and Reporting">
246
+
<t>
247
+
The party that is providing the schema and input may not be the same party that is performing the validation; in this case, there should be a standard way to abstract away the validator interface, and report the results of a validation operation (validation result, annotations, and errors).
Application developers may wish to express a wide variety of constraints that would be impractical to require every validator to implement.
@@ -199,7 +260,7 @@ expressed as a context-free grammar that follows JSON
199
260
200
261
<sectiontitle="Use cases for extensions">
201
262
<t>
202
-
This section lists use cases that are not required for interoperability in media type handling, but which should be defined as standard extensions to maximize support and feature interoperability.
263
+
This section lists use cases that are not required for interoperability and are not standardized, but fall within the objectives and could be standardized in the future.
203
264
As specified in <xreftarget="extension-points">"Extension points,"</xref>
204
265
validators should gracefully degrade in the presence of extensions that they do not support.
205
266
</t>
@@ -235,10 +296,10 @@ expressed as a context-free grammar that follows JSON
235
296
Sometimes it's desirable to require formatting that does not impact the application-level meaning of the document, but instead specifies requirements purely for aesthetic or compatibility reasons.
236
297
</t>
237
298
<t>
238
-
For example, for security reasons, a linter may need to ensure that a JSON document does not contain the string "</script" but instead contains a character escape such as "<\/script". This would ensure that, if the JSON were to be embedded in a <script> tag, that it would not have any part that could be interpreted as HTML.
299
+
For example, for security reasons, a linter may need to ensure that a JSON document does not contain the string "<tt></script</tt>" but is written instead with a character escape such as "<tt><\/script</tt>". This would ensure that, if the JSON were to be embedded in a <tt><script></tt> tag, that it would not have any part that could close the tag and start being interpreted as HTML.
239
300
</t>
240
301
<t>
241
-
This is not a core part of JSON because it may violate the semantics of JSON, adding an ability to distinguish two document that JSON requires be equal to the receiving application.
302
+
This is not a core part of JSON because it may violate the semantics of JSON, adding an ability to distinguish two documents that are supposed to be equal to the receiving application.
0 commit comments