-
-
Notifications
You must be signed in to change notification settings - Fork 273
/
jsonschema-core.xml
2179 lines (2093 loc) · 114 KB
/
jsonschema-core.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!ENTITY RFC2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC3986 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3986.xml">
<!ENTITY RFC6839 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6839.xml">
<!ENTITY RFC6901 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6901.xml">
<!ENTITY RFC7049 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7049.xml">
<!ENTITY RFC8259 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8259.xml">
<!ENTITY RFC7231 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7231.xml">
<!ENTITY RFC8288 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8288.xml">
<!ENTITY ldp SYSTEM "https://xml2rfc.tools.ietf.org/public/rfc/bibxml4/reference.W3C.REC-ldp-20150226.xml">
<!ENTITY fragid-best-practices SYSTEM "https://xml2rfc.tools.ietf.org/public/rfc/bibxml4/reference.W3C.WD-fragid-best-practices-20121025.xml">
]>
<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc strict="no"?>
<?rfc rfcedstyle="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes" ?>
<rfc category="info" docName="draft-handrews-json-schema-02" ipr="trust200902">
<front>
<title abbrev="JSON Schema">JSON Schema: A Media Type for Describing JSON Documents</title>
<author fullname="Austin Wright" initials="A" surname="Wright" role="editor">
<address>
<email>aaa@bzfx.net</email>
</address>
</author>
<author fullname="Henry Andrews" initials="H" surname="Andrews" role="editor">
<address>
<postal>
<street></street>
<city>San Francisco</city>
<region>CA</region>
<country>USA</country>
</postal>
<email>henry@cloudflare.com</email>
</address>
</author>
<date year="2018"/>
<workgroup>Internet Engineering Task Force</workgroup>
<keyword>JSON</keyword>
<keyword>Schema</keyword>
<keyword>Hyper Schema</keyword>
<keyword>Hypermedia</keyword>
<abstract>
<t>
JSON Schema defines the media type "application/schema+json", a JSON-based format
for describing the structure of JSON data.
JSON Schema asserts what a JSON document must look like,
ways to extract information from it,
and how to interact with it.
The "application/schema-instance+json" media type provides additional
feature-rich integration with "application/schema+json" beyond what can be offered
for "application/json" documents.
</t>
</abstract>
<note title="Note to Readers">
<t>
The issues list for this draft can be found at
<eref target="https://github.com/json-schema-org/json-schema-spec/issues"/>.
</t>
<t>
For additional information, see <eref target="http://json-schema.org/"/>.
</t>
<t>
To provide feedback, use this issue tracker, the communication methods listed on the
homepage, or email the document editors.
</t>
</note>
</front>
<middle>
<section title="Introduction">
<t>
JSON Schema is a JSON media type for defining the structure of JSON data. JSON Schema
is intended to define validation, documentation, hyperlink navigation, and interaction
control of JSON data.
</t>
<t>
This specification defines JSON Schema core terminology and mechanisms, including
pointing to another JSON Schema by reference,
dereferencing a JSON Schema reference,
and specifying the vocabulary being used.
</t>
<t>
Other specifications define the vocabularies that perform assertions about validation,
linking, annotation, navigation, and interaction.
</t>
</section>
<section title="Conventions and Terminology">
<t>
<!-- The text in this section has been copied from the official boilerplate,
and should not be modified.-->
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
"SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
interpreted as described in <xref target="RFC2119">RFC 2119</xref>.
</t>
<t>
The terms "JSON", "JSON text", "JSON value", "member", "element", "object", "array",
"number", "string", "boolean", "true", "false", and "null" in this document are to
be interpreted as defined in <xref target="RFC8259">RFC 8259</xref>.
</t>
</section>
<section title="Overview">
<t>
This document proposes a new media type "application/schema+json" to identify a JSON
Schema for describing JSON data.
It also proposes a further optional media type, "application/schema-instance+json",
to provide additional integration features.
JSON Schemas are themselves JSON documents.
This, and related specifications, define keywords allowing authors to describe JSON
data in several ways.
</t>
<section title="Keyword Behaviors">
<t>
JSON Schema keywords fall into several general behavior categories.
Assertions validate that an instance satisfies constraints, producing
a boolean result. Annotations attach information that applications
may use in any way they see fit.
Applicators apply subschemas to parts of the instance and combine
their results.
</t>
<t>
Extension keywords SHOULD stay within these categories, keeping in mind
that annotations in particular are extremely flexible. Complex behavior
is usually better delegated to applications on the basis of annotation
data than implemented directly as schema keywords. However, extension
keywords MAY define other behaviors for specialized purposes.
</t>
<t>
Evaluating an instance against a schema involves processing all of the
keywords in the schema against the appropriate locations within the instance.
Typically, applicator keywords are processed until a schema object with no
applicators (and therefore no subschemas) is reached. The appropriate
location in the instance is evaluated against the assertion and
annotation keywords in the schema object, and their results are gathered
into the parent schema according to the rules of the applicator.
</t>
<t>
Evaluation of a parent schema object can complete once all of its
subschemas have been evaluated, although in some circumstance evaluation
may be short-circuited due to assertion results.
</t>
<section title="Keyword Interactions">
<t>
Keyword behavior MAY be defined in terms of the annotation results
of <xref target="root">subschemas</xref> and/or adjacent keywords.
Such keywords MUST NOT result in a circular dependency.
Keywords MAY modify their behavior based on the presence or absence
of another keyword in the same
<xref target="schema-document">schema object</xref>.
</t>
</section>
<section title="Default Behaviors">
<t>
A missing keyword MUST NOT produce a false assertion result, MUST
NOT produce annotation results, and MUST NOT cause any other schema
to be evaluated as part of its own behavioral definition.
However, given that missing keywords do not contribute annotations,
the lack of annotation results may indirectly change the behavior
of other keywords.
</t>
<t>
In some cases, the missing keyword assertion behavior of a keyword is
identical to that produced by a certain value, and keyword definitions
SHOULD note such values where known. However, even if the value which
produces the default behavior would produce annotation results if
present, the default behavior still MUST NOT result in annotations.
</t>
<t>
Because annotation collection can add significant cost in terms of both
computation and memory, implementations MAY opt out of this feature.
Keywords known to an implementation to have assertion or applicator behavior
that depend on annotation results MUST then be treated as errors, unless
an alternate implementation producing the same behavior is available.
Keywords of this sort SHOULD describe reasonable alternate approaches
when appropriate. This approach is demonstrated by the
"<xref target="additionalItems" format="title"/>" and
"<xref target="additionalProperties" format="title"/>" keywords in this
document.
</t>
</section>
<section title="Applicators" anchor="applicators">
<t>
Applicators allow for building more complex schemas than can be accomplished
with a single schema object. Evaluation of an instance against a
<xref target="schema-document">schema document</xref> begins by applying
the <xref target="root">root schema</xref> to the complete instance
document. From there, keywords known as applicators are used to determine
which additional schemas are applied. Such schemas may be applied in-place
to the current location, or to a child location.
</t>
<t>
The schemas to be applied may be present as subschemas comprising all or
part of the keyword's value. Alternatively, an applicator may refer to
a schema elsewhere in the same schema document, or in a different one.
The mechanism for identifying such referred schemas is defined by the
keyword.
</t>
<t>
Applicator keywords also define how subschema or referred schema
boolean <xref target="assertions">assertion</xref>
results are modified and/or combined to produce the boolean result
of the applicator. Applicators may apply any boolean logic operation
to the assertion results of subschemas, but MUST NOT introduce new
assertion conditions of their own.
</t>
<t>
<xref target="annotations">Annotation</xref> results are
combined according to the rules specified by each annotation keyword.
</t>
</section>
<section title="Assertions" anchor="assertions">
<t>
JSON Schema can be used to assert constraints on a JSON document, which
either passes or fails the assertions. This approach can be used to validate
conformance with the constraints, or document what is needed to satisfy them.
</t>
<t>
JSON Schema implementations produce a single boolean result when evaluating
an instance against schema assertions.
</t>
<t>
An instance can only fail an assertion that is present in the schema.
</t>
<section title="Assertions and Instance Primitive Types">
<t>
Most assertions only constrain values within a certain
primitive type. When the type of the instance is not of the type
targeted by the keyword, the instance is considered to conform
to the assertion.
</t>
<t>
For example, the "maxLength" keyword from the companion validation
vocabulary will only restrict certain strings
(that are too long) from being valid. If the instance is a number,
boolean, null, array, or object, then it is valid against this assertion.
</t>
</section>
</section>
<section title="Annotations" anchor="annotations">
<t>
JSON Schema can annotate an instance with information, whenever the instance
validates against the schema object containing the annotation, and all of its
parent schema objects. The information can be a simple value, or can be
calculated based on the instance contents.
</t>
<t>
Annotations are attached to specific locations in an instance.
Since many subschemas can be applied to any single
location, annotation keywords need to specify any unusual handling of
multiple applicable occurrences of the keyword with different values.
</t>
<t>
The default behavior is simply to collect all values in a list in
indeterminate order. Given the extensibility of keywords, including
applicators, it is not possible to define a universally predictable
order of processing.
</t>
<t>
Unlike assertion results, annotation data can take a wide variety of forms,
which are provided to applications to use as they see fit. JSON Schema
implementations are not expected to make use of the collected information
on behalf of applications.
</t>
<t>
While "short-circuit" evaluation is possible for assertions, collecting
annotations requires examining all schemas that apply to an instance
location, even if they cannot change the overall assertion result.
</t>
</section>
</section>
<section title="Schema Vocabularies" anchor="vocabulary">
<t>
A JSON Schema vocabulary is a set of keywords defined for a particular
purpose. The vocabulary specifies the meaning of its keywords as
assertions, annotations, and/or any vocabulary-defined keyword category.
</t>
<t>
Several vocabularies are provided as
standards in this and closely related documents. These vocabularies
are used with the core keywords defined as fundamental to the
"application/schema+json" media type.
</t>
<t>
Schema authors are encouraged to define their own vocabularies for
domain-specific concepts. A vocabulary need not be a standard to
be re-usable, although users of extension vocabularies MUST NOT
assume that any JSON Schema implementation can support the vocabulary
unless it specifically documents such support.
</t>
<section title="Subschema Application">
<t>
This vocabulary provides keywords for applying subschemas to the
instance in various ways. It is defined in this document, and
it is RECOMMENDED that all JSON Schema implementations support it.
All other vocabularies in this section are designed to be used
alongside the subschema application vocabulary.
</t>
<t>
Without this vocabulary or an equivalent one, JSON Schema can only
be applied to a JSON document as a whole. In most cases, schema
keywords need to be applied to specific object properties or array items.
</t>
</section>
<section title="Validation">
<t>
This vocabulary describes the structure of a JSON document
(for instance, required properties and length limitations).
Applications can use this information to validate instances (check that
constraints are met), or inform interfaces to collect user input
such that the constraints are satisfied.
</t>
<t>
Validation behaviour and keywords are specified in
<xref target="json-schema-validation">a separate document</xref>.
</t>
</section>
<section title="Basic Meta-Data">
<t>
A small set of annotation keywords are defined in
<xref target="json-schema-validation">the validation specification</xref>
to allow associating common kinds of meta-data with an instance.
</t>
</section>
<section title="Hypermedia and Linking">
<t>
JSON Hyper-Schema produces hyperlinks as annotations available for
use with a JSON document. It supports resolving URI Templates
and describing the resource and data submission formats required
to use an API.
</t>
<t>
Hyper-schema behaviour and keywords are specified in
<xref target="json-hyper-schema">a separate document</xref>.
</t>
</section>
</section>
</section>
<section title="Definitions">
<section title="JSON Document">
<t>
A JSON document is an information resource (series of octets) described by the
application/json media type.
</t>
<t>
In JSON Schema, the terms "JSON document", "JSON text", and "JSON value" are
interchangeable because of the data model it defines.
</t>
<t>
JSON Schema is only defined over JSON documents. However, any document or memory
structure that can be parsed into or processed according to the JSON Schema data
model can be interpreted against a JSON Schema, including media types like
<xref target="RFC7049">CBOR</xref>.
</t>
</section>
<section title="Instance">
<t>
A JSON document to which a schema is applied is known as an "instance".
</t>
<section title="Instance Data Model">
<t>
JSON Schema interprets documents according to a data model. A JSON value
interpreted according to this data model is called an "instance".
</t>
<t>
An instance has one of six primitive types, and a range of possible values
depending on the type:
<list style="hanging">
<t hangText="null:">A JSON "null" production</t>
<t hangText="boolean:">A "true" or "false" value, from the JSON "true" or "false" productions</t>
<t hangText="object:">An unordered set of properties mapping a string to an instance, from the JSON "object" production</t>
<t hangText="array:">An ordered list of instances, from the JSON "array" production</t>
<t hangText="number:">An arbitrary-precision, base-10 decimal number value, from the JSON "number" production</t>
<t hangText="string:">A string of Unicode code points, from the JSON "string" production</t>
</list>
</t>
<t>
Whitespace and formatting concerns, including different lexical
representations of numbers that are equal within the data model, are thus
outside the scope of JSON Schema. JSON Schema
<xref target="vocabulary">vocabularies</xref> that wish
to work with such differences in lexical representations SHOULD define
keywords to precisely interpret formatted strings within the data model
rather than relying on having the original JSON representation Unicode
characters available.
</t>
<t>
Since an object cannot have two properties with the same key, behavior for a
JSON document that tries to define two properties (the "member" production) with
the same key (the "string" production) in a single object is undefined.
</t>
<t>
Note that JSON Schema vocabularies are free to define their own extended
type system. This should not be confused with the core data model types
defined here. As an example, "integer" is a reasonable type for a
vocabulary to define as a value for a keyword, but the data model
makes no distinction between integers and other numbers.
</t>
</section>
<section title="Instance Media Types">
<t>
JSON Schema is designed to fully work with "application/json" documents,
as well as media types using the "+json" structured syntax suffix.
</t>
<t>
Some functionality that is useful for working with schemas is
defined by each media type, namely media type parameters and
URI fragment identifier syntax and semantics. These features are
useful in content negotiation and in calculating URIs for specific
locations within an instance, respectively.
</t>
<t>
This specification defines the "application/schema-instance+json"
media type in order to allow instance authors to take full advantage
of parameters and fragment identifiers for these purposes.
</t>
</section>
<section title="Instance Equality">
<t>
Two JSON instances are said to be equal if and only if they are of the same type
and have the same value according to the data model. Specifically, this means:
<list>
<t>both are null; or</t>
<t>both are true; or</t>
<t>both are false; or</t>
<t>both are strings, and are the same codepoint-for-codepoint; or</t>
<t>both are numbers, and have the same mathematical value; or</t>
<t>both are arrays, and have an equal value item-for-item; or</t>
<t>both are objects, and each property in one has exactly one property with
a key equal to the other's, and that other property has an equal
value.</t>
</list>
</t>
<t>
Implied in this definition is that arrays must be the same length,
objects must have the same number of members,
properties in objects are unordered,
there is no way to define multiple properties with the same key,
and mere formatting differences (indentation, placement of commas, trailing
zeros) are insignificant.
</t>
</section>
</section>
<section title="JSON Schema Documents" anchor="schema-document">
<t>
A JSON Schema document, or simply a schema, is a JSON document used to describe
an instance.
A schema is itself interpreted as an instance, but SHOULD always be given
the media type "application/schema+json" rather than
"application/schema-instance+json". The "application/schema+json" media
type is defined to offer a superset of the media type parameter and
fragment identifier syntax and semantics provided by
"application/schema-instance+json".
</t>
<t>
A JSON Schema MUST be an object or a boolean.
</t>
<section title="JSON Schema Objects and Keywords">
<t>
Object properties that are applied to the instance are called keywords,
or schema keywords. Broadly speaking, keywords fall into one
of three categories:
<list style="hanging">
<t hangText="assertions:">
produce a boolean result when applied to an instance
</t>
<t hangText="annotations:">
attach information to an instance for application use
</t>
<t hangText="applicators:">
apply one or more subschemas to a particular location
in the instance, and combine or modify their results
</t>
</list>
</t>
<t>
Keywords may fall into multiple categories, although applicators
SHOULD only produce assertion results based on their subschemas'
results. They should not define additional constraints independent
of their subschemas.
</t>
<t>
Extension keywords, meaning those defined outside of this document
and its companions, are free to define other behaviors as well.
</t>
<t>
A JSON Schema MAY contain properties which are not schema keywords.
Unknown keywords SHOULD be ignored.
</t>
<t>
An empty schema is a JSON Schema with no properties, or only unknown
properties.
</t>
</section>
<section title="Boolean JSON Schemas">
<t>
The boolean schema values "true" and "false" are trivial schemas that
always produce themselves as assertions results, regardless of the
instance value. They never produce annotation results.
</t>
<t>
These boolean schemas exist to clarify schema author intent and
facilitate schema processing optimizations. They behave identically
to the following schema objects (where "not" is part of the
subschema application vocabulary defined in this document).
<list style="hanging">
<t hangText="true:">
Always passes validation, as if the empty schema {}
</t>
<t hangText="false:">
Always fails validation, as if the schema { "not":{} }
</t>
</list>
While the empty schema object is unambiguous, there are many
possible equivalents to the "false" schema. Using the boolean
values ensures that the intent is clear to both human readers
and implementations.
</t>
</section>
<section title="Root Schema and Subschemas" anchor="root">
<t>
The root schema is the schema that comprises the entire JSON document
in question.
</t>
<t>
Some keywords take schemas themselves, allowing JSON Schemas to be nested:
</t>
<figure>
<artwork>
<![CDATA[
{
"title": "root",
"items": {
"title": "array item"
}
}
]]>
</artwork>
</figure>
<t>
In this example document, the schema titled "array item" is a subschema,
and the schema titled "root" is the root schema.
</t>
<t>
As with the root schema, a subschema is either an object or a boolean.
</t>
</section>
<section title="Lexical Scope and Dynamic Scope">
<t>
While most JSON Schema keywords can be evaluated on their own,
or at most need to take into account the values or results of
adjacent keywords in the same schema object, a few have more
complex behavior.
</t>
<t>
The lexical scope of a keyword is deterimined by the nested JSON
data structure of objects and arrays. The largest such scope
is an entire schema document. The smallest scope is a single
schema object with no subschemas.
</t>
<t>
Keywords MAY be defined with a partial value, such as a URI-reference,
which must be resolved against another value, such as another
URI-reference or a full URI, which is found through the lexical
structure of the JSON document. The "$id" core keyword and
the "base" JSON Hyper-Schema keyword are examples of this sort
of behavior. Additionally, "$ref" and "$recursiveRef" from
this specification resolve their values in this way, although
they do not change how further values are resolved.
</t>
<t>
Note that some keywords, such as "$schema", apply to the lexical
scope of the entire schema document, and therefore MUST only
appear in the document's root schema.
</t>
<t>
Other keywords may take into account the dynamic scope that
exists during the evaluation of a schema, typically together
with an instance document. The outermost dynamic scope is the
root schema of the schema document in which processing begins.
<cref>
Or should this be the schema object at which processing
begins, even if it is not a root? This has some implications
for the case where "$recursiveAnchor" is only allowed in the
root schema but processing begins in a subschema.
</cref>
</t>
<t>
Lexical and dynamic scopes align until a reference keyword
is encountered. While following the reference keyword jumps
from one lexical scope into a different one, from the perspective
of dynamic scope, following reference is no different from descending
into a subschema present as a value. A keyword on the far side of
that reference that resolves information through the dynamic scope
will consider the originating side of the reference to be their
dynamic parent, rather than examining the local lexically enclosing parent.
</t>
<t>
The concept of dynamic scope is primarily used with "$recursiveRef"
and "$recursiveAnchor", and should be considered and advanced feature
and used with caution when defining additional keywords.
</t>
</section>
<section title="Referred and Referring Schemas" anchor="referred">
<t>
As noted in <xref target="applicators" />, an applicator keyword may
refer to a schema to be applied, rather than including it as a
subschema in the applicator's value. In such situations, the
schema being applied is known as the referred (or referenced) schema,
while the schema containing the applicator keyword is the referring
(or referencing) schema.
</t>
<t>
While root schemas and subschemas are static concepts based on a
schema's position within a schema document, referred and referring
schemas are dynamic. Different pairs of schemas may find themselves
in various referred and referring arrangements during the evaluation
of an instance against a schema.
</t>
<t>
For some by-reference applicators, such as
<xref target="ref">"$ref"</xref>, the referenced schema can be determined
by static analysis of the schema document's lexical scope. Others,
such as "$recursiveRef" and "$recursiveAnchor", may make use of dynamic
scoping, and therefore only be resolvable in the process of evaluating
the schema with an instance.
</t>
</section>
</section>
</section>
<section title="Fragment Identifiers" anchor="fragments">
<t>
In accordance with section 3.1 of <xref target="RFC6839"></xref>,
the syntax and semantics of fragment identifiers specified for
any +json media type SHOULD be as specified for "application/json".
(At publication of this document, there is no fragment identification
syntax defined for "application/json".)
</t>
<t>
Additionally, the "application/schema+json" media type supports two
fragment identifier structures: plain names and JSON Pointers.
The "application/schema-instance+json" media type supports one
fragment identifier structure: JSON Pointers.
</t>
<t>
The use of JSON Pointers as URI fragment identifiers is described in
<xref target="RFC6901">RFC 6901</xref>.
For "application/schema+json", which supports two fragment identifier syntaxes,
fragment identifiers matching the JSON Pointer syntax, including the empty string,
MUST be interpreted as JSON Pointer fragment identifiers.
</t>
<t>
Per the W3C's
<xref target="W3C.WD-fragid-best-practices-20121025">best practices for fragment identifiers</xref>,
plain name fragment identifiers in "application/schema+json" are reserved for referencing
locally named schemas. All fragment identifiers that do
not match the JSON Pointer syntax MUST be interpreted as
plain name fragment identifiers.
</t>
<t>
Defining and referencing a plain name fragment identifier within an
"application/schema+json" document are specified
in the <xref target="id-keyword">"$id" keyword</xref> section.
</t>
<t>
</t>
</section>
<section title="General Considerations">
<section title="Range of JSON Values">
<t>
An instance may be any valid JSON value as defined by <xref target="RFC8259">JSON</xref>.
JSON Schema imposes no restrictions on type: JSON Schema can describe any JSON
value, including, for example, null.
</t>
</section>
<section title="Programming Language Independence" anchor="language">
<t>
JSON Schema is programming language agnostic, and supports the full range of
values described in the data model.
Be aware, however, that some languages and JSON parsers may not be able to
represent in memory the full range of values describable by JSON.
</t>
</section>
<section title="Mathematical Integers" anchor="integers">
<t>
Some programming languages and parsers use different internal representations
for floating point numbers than they do for integers.
</t>
<t>
For consistency, integer JSON numbers SHOULD NOT be encoded with a fractional
part.
</t>
</section>
<section title="Regular Expressions" anchor="regex">
<t>
Keywords MAY use regular expressions to express constraints, or constrain
the instance value to be a regular expression.
These regular expressions SHOULD be valid according to the
<xref target="ecma262">ECMA 262</xref> regular expression dialect.
</t>
<t>
Furthermore, given the high disparity in regular expression constructs support,
schema authors SHOULD limit themselves to the following regular expression
tokens:
<list>
<t>individual Unicode characters, as defined by the <xref
target="RFC8259">JSON specification</xref>;</t>
<t>simple character classes ([abc]), range character classes ([a-z]);</t>
<t>complemented character classes ([^abc], [^a-z]);</t>
<t>simple quantifiers: "+" (one or more), "*" (zero or more), "?" (zero or
one), and their lazy versions ("+?", "*?", "??");</t>
<t>range quantifiers: "{x}" (exactly x occurrences), "{x,y}" (at least x, at
most y, occurrences), {x,} (x occurrences or more), and their lazy
versions;</t>
<t>the beginning-of-input ("^") and end-of-input ("$") anchors;</t>
<t>simple grouping ("(...)") and alternation ("|").</t>
</list>
</t>
<t>
Finally, implementations MUST NOT take regular expressions to be
anchored, neither at the beginning nor at the end. This means, for instance,
the pattern "es" matches "expression".
</t>
</section>
<section title="Extending JSON Schema">
<t>
Additional schema keywords and schema vocabularies MAY be defined
by any entity. Save for explicit agreement, schema authors SHALL NOT
expect these additional keywords and vocabularies to be supported by
implementations that do not explicitly document such support.
Implementations SHOULD ignore keywords they do not support.
</t>
<t>
Vocabulary authors SHOULD
take care to avoid keyword name collisions if the vocabulary is intended
for broad use, and potentially combined with other vocabularies. JSON
Schema does not provide any formal namespacing system, but also does
not constrain keyword names, allowing for any number of namespacing
approaches.
</t>
<t>
Vocabularies may build on each other, such as by defining the behavior
of their keywords with respect to the behavior of keywords from another
vocabulary, or by using a keyword from another vocabulary with
a restricted or expanded set of acceptable values. Not all such
vocabulary re-use will result in a new vocabulary that is compatible
with the vocabulary on which it is built. Vocabulary authors SHOULD
clearly document what level of compatibility, if any, is expected.
</t>
<t>
A schema that itself describes a schema is called a meta-schema.
Meta-schemas are used to validate JSON Schemas and specify which vocabulary
it is using.
</t>
<t>
Authors of extensions to JSON Schema are encouraged to write their own
meta-schemas, which extend the existing meta-schemas using "allOf".
This extended meta-schema SHOULD be referenced using the "$schema" keyword, to
allow tools to follow the correct behaviour.
</t>
<t>
The recursive nature of meta-schemas makes the "$recursiveAnchor"
and "$recursiveRef" keywords particularly useful for such extensions,
as can be seen in the JSON Hyper-Schema meta-schema.
</t>
</section>
</section>
<section title='The "$schema" Keyword'>
<!-- TODO a custom $schema keyword might also be used to enforce minimum required functionality of a validator -->
<t>
The "$schema" keyword is both used as a JSON Schema version identifier and the
location of a resource which is itself a JSON Schema, which describes any schema
written for this particular version.
</t>
<t>
The value of this keyword MUST be a <xref target="RFC3986">URI</xref>
(containing a scheme) and this URI MUST be normalized.
The current schema MUST be valid against the meta-schema identified by this URI.
</t>
<t>
If this URI identifies a retrievable resource, that resource SHOULD be of
media type "application/schema+json".
</t>
<t>
The "$schema" keyword SHOULD be used in a root schema.
It MUST NOT appear in subschemas.
</t>
<t>
<cref>
Using multiple "$schema" keywords in the same document would imply that the
vocabulary and therefore behavior can change within a document. This would
necessitate resolving a number of implementation concerns that have not yet
been clearly defined. So, while the pattern of using "$schema" only in root
schemas is likely to remain the best practice for schema authoring,
implementation behavior is subject to be revised or liberalized in
future drafts.
</cref>
<!--
In particular, the process of validating an instance, including validating a
schema as an instance against its meta-schema, only allows for a single set
of rules across the entire instance document. There is no equivalent of
changing the meta-schema partway through the validation for non-schema
instances.
-->
</t>
<t>
Values for this property are defined in other documents and by other parties.
JSON Schema implementations SHOULD implement support for current and previous
published drafts of JSON Schema vocabularies as deemed reasonable.
</t>
</section>
<section title="Base URI and Dereferencing">
<t>
To differentiate between schemas in a vast ecosystem, schemas are
identified by <xref target="RFC3986">URI</xref>, and can embed references to other schemas by specifying their URI.
</t>
<section title="Initial Base URI">
<t>
<xref target="RFC3986">RFC3986 Section 5.1</xref> defines how to determine the
default base URI of a document.
</t>
<t>
Informatively, the initial base URI of a schema is the URI at which it was
found, or a suitable substitute URI if none is known.
</t>
</section>
<section title='The "$id" Keyword' anchor="id-keyword">
<t>
The "$id" keyword defines a URI for the schema, and the base URI that
other URI references within the schema are resolved against.
A subschema's "$id" is resolved against the base URI of its parent schema.
If no parent sets an explicit base with "$id", the base URI is that of the
entire document, as determined per
<xref target="RFC3986">RFC 3986 section 5</xref>.
</t>
<t>
If present, the value for this keyword MUST be a string, and MUST represent a
valid <xref target="RFC3986">URI-reference</xref>.
This value SHOULD be normalized, and SHOULD NOT be an empty fragment <#>
or an empty string <>.
</t>
<section title="Identifying the root schema">
<t>
The root schema of a JSON Schema document SHOULD contain an "$id" keyword with
an <xref target="RFC3986">absolute-URI</xref> (containing a scheme, but no fragment),
or this absolute URI but with an empty fragment.
<!-- All of the standard meta-schemas use an empty fragment in their id/$id values. -->
</t>
</section>
<section title="Changing the base URI within a schema file">
<t>
When an "$id" sets the base URI, the object containing that "$id" and all of
its subschemas can be identified by using a JSON Pointer fragment starting
from that location. This is true even of subschemas that further change the
base URI. Therefore, a single subschema may be accessible by multiple URIs,
each consisting of base URI declared in the subschema or a parent, along with
a JSON Pointer fragment identifying the path from the schema object that
declares the base to the subschema being identified. Examples of this are
shown in section <xref target="idExamples" format="counter"></xref>.
</t>
</section>
<section title="Location-independent identifiers">
<t>
Using JSON Pointer fragments requires knowledge of the structure of the schema.
When writing schema documents with the intention to provide re-usable
schemas, it may be preferable to use a plain name fragment that is not tied to
any particular structural location. This allows a subschema to be relocated
without requiring JSON Pointer references to be updated.
</t>
<t>
To specify such a subschema identifier,
the "$id" keyword is set to a URI reference with a plain name fragment (not a JSON Pointer fragment).
This value MUST begin with the number sign that specifies a fragment ("#"),
then a letter ([A-Za-z]),
followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
colons (":"), or periods (".").
</t>
<t>
The effect of using a fragment in "$id" that isn't blank or doesn't follow the
plain name syntax is undefined.
<cref>
How should an "$id" URI reference containing a fragment with other components
be interpreted? There are two cases: when the other components match
the current base URI and when they change the base URI.
</cref>
</t>
</section>
<section title="Schema identification examples" anchor="idExamples">
<figure>
<preamble>
Consider the following schema, which shows "$id" being used to identify
the root schema, change the base URI for subschemas, and assign plain
name fragments to subschemas:
</preamble>
<artwork>
<![CDATA[
{
"$id": "http://example.com/root.json",
"$defs": {
"A": { "$id": "#foo" },
"B": {
"$id": "other.json",
"$defs": {
"X": { "$id": "#bar" },
"Y": { "$id": "t/inner.json" }
}
},
"C": {
"$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
}
}
}
]]>
</artwork>
</figure>
<t>
The schemas at the following URI-encoded <xref target="RFC6901">JSON
Pointers</xref> (relative to the root schema) have the following
base URIs, and are identifiable by any listed URI in accordance with
Section <xref target="fragments" format="counter"></xref> above:
</t>
<t>
<list style="hanging">
<t hangText="# (document root)">
<list>
<t>http://example.com/root.json</t>
<t>http://example.com/root.json#</t>
</list>
</t>
<t hangText="#/$defs/A">
<list>
<t>http://example.com/root.json#foo</t>
<t>http://example.com/root.json#/$defs/A</t>
</list>
</t>
<t hangText="#/$defs/B">
<list>
<t>http://example.com/other.json</t>
<t>http://example.com/other.json#</t>
<t>http://example.com/root.json#/$defs/B</t>
</list>
</t>
<t hangText="#/$defs/B/$defs/X">
<list>
<t>http://example.com/other.json#bar</t>
<t>http://example.com/other.json#/$defs/X</t>
<t>http://example.com/root.json#/$defs/B/$defs/X</t>
</list>
</t>
<t hangText="#/$defs/B/$defs/Y">
<list>
<t>http://example.com/t/inner.json</t>
<t>http://example.com/t/inner.json#</t>
<t>http://example.com/other.json#/$defs/Y</t>
<t>http://example.com/root.json#/$defs/B/$defs/Y</t>
</list>
</t>
<t hangText="#/$defs/C">
<list>
<t>urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f</t>
<t>urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f#</t>