forked from json-schema-org/json-schema-spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonschema-validation.xml
1268 lines (1185 loc) · 60.7 KB
/
jsonschema-validation.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 RFC1034 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.1034.xml">
<!ENTITY RFC2045 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2045.xml">
<!ENTITY RFC2046 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2046.xml">
<!ENTITY RFC2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC2673 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2673.xml">
<!ENTITY RFC3339 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3339.xml">
<!ENTITY RFC3986 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3986.xml">
<!ENTITY RFC3987 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3987.xml">
<!ENTITY RFC4291 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4291.xml">
<!ENTITY RFC4329 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4329.xml">
<!ENTITY RFC4648 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4648.xml">
<!ENTITY RFC5322 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5322.xml">
<!ENTITY RFC5890 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5890.xml">
<!ENTITY RFC5891 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5891.xml">
<!ENTITY RFC6531 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6531.xml">
<!ENTITY RFC6570 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6570.xml">
<!ENTITY RFC6901 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6901.xml">
<!ENTITY RFC8259 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8259.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-validation-02" ipr="trust200902">
<front>
<title abbrev="JSON Schema Validation">
JSON Schema Validation: A Vocabulary for Structural Validation of JSON
</title>
<author fullname="Austin Wright" initials="A" surname="Wright" role="editor">
<address>
<email>[email protected]</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>[email protected]</email>
</address>
</author>
<author fullname="Ben Hutton" initials="B" surname="Hutton" role="editor">
<organization>Wellcome Sanger Institute</organization>
<address>
<email>[email protected]</email>
</address>
</author>
<author fullname="Geraint Luff" initials="G" surname="Luff">
<address>
<postal>
<street></street>
<city>Cambridge</city>
<country>UK</country>
</postal>
<email>[email protected]</email>
</address>
</author>
<date year="2018"/>
<workgroup>Internet Engineering Task Force</workgroup>
<keyword>JSON</keyword>
<keyword>Schema</keyword>
<keyword>validation</keyword>
<abstract>
<t>
JSON Schema (application/schema+json) has several purposes, one of which is JSON
instance validation.
This document specifies a vocabulary for JSON Schema to describe the meaning of JSON
documents, provide hints for user interfaces working with JSON data, and to make
assertions about what a valid document must look like.
</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 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.
</t>
<t>
This specification will use the concepts, syntax, and terminology defined
by the <xref target="json-schema">JSON Schema core</xref> specification.
</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>
This specification uses the term "container instance" to refer to both array and
object instances. It uses the term "children instances" to refer to array elements
or object member values.
</t>
<t>
Elements in an array value are said to be unique if no two elements of this array
are <xref target="json-schema">equal</xref>.
</t>
</section>
<section title="Overview">
<t>
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.
</t>
<t>
Each schema object is independently evaluated against each instance location
to which it applies. This greatly simplifies the implementation requirements
for validators by ensuring that they do not need to maintain state across
the document-wide validation process.
</t>
<t>
This specification defines a set of assertion keywords, as well as a small vocabulary
of metadata keywords that can be used to annotate the JSON instance with
useful information. The <xref target="format" /> and <xref target="content" />
keywords are also useful as annotations as well as being optional assertions,
as they convey additional usage guidance for the instance data.
</t>
</section>
<section title="Interoperability Considerations">
<section title="Validation of String Instances">
<t>
It should be noted that 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.
</t>
</section>
<section title="Validation of Numeric Instances">
<t>
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.
</t>
</section>
<section title="Regular Expressions" anchor="regexInterop">
<t>
Keywords that use regular expressions, or constrain the instance value
to be a regular expression, are subject to the interoperability
considerations for regular expressions in the
<xref target="json-schema">JSON Schema Core</xref> specification.
</t>
</section>
</section>
<section title="Meta-Schema">
<t>
The current URI for the JSON Schema Validation meta-schema is
<eref target="http://json-schema.org/draft-08/schema#"/>.
This meta-schema describes the core keywords, the subschema application
vocabulary from the core specification, and all keywords
defined by this specification. All implementations of this specification
SHOULD support the subschema application vocabulary, and MUST NOT
implement behavior that contradicts that vocabulary.
</t>
</section>
<section title="Validation Keywords">
<t>
Validation keywords in a schema impose requirements for successful validation of an
instance. These keywords are all assertions without any annotation behavior.
</t>
<section title="Validation Keywords for Any Instance Type" anchor="general">
<section title="type">
<t>
The value of this keyword MUST be either a string or an array. If it is
an array, elements of the array MUST be strings and MUST be unique.
</t>
<t>
String values MUST be one of the six primitive types
("null", "boolean", "object", "array", "number", or "string"),
or "integer" which matches any number with a zero fractional part.
</t>
<t>
An instance validates if and only if the instance is in any of the sets listed
for this keyword.
</t>
</section>
<section title="enum">
<t>
The value of this keyword MUST be an array. This array SHOULD have at
least one element. Elements in the array SHOULD be unique.
</t>
<t>
An instance validates successfully against this keyword if its value is
equal to one of the elements in this keyword's array value.
</t>
<t>
Elements in the array might be of any type, including null.
</t>
</section>
<section title="const">
<t>
The value of this keyword MAY be of any type, including null.
</t>
<t>
An instance validates successfully against this keyword if its value is
equal to the value of the keyword.
</t>
</section>
</section>
<section title="Validation Keywords for Numeric Instances (number and integer)"
anchor="numeric">
<section title="multipleOf">
<t>
The value of "multipleOf" MUST be a number, strictly greater than 0.
</t>
<t>
A numeric instance is valid only if division by this keyword's value results in
an integer.
</t>
</section>
<section title="maximum">
<t>
The value of "maximum" MUST be a number, representing an inclusive upper limit
for a numeric instance.
</t>
<t>
If the instance is a number, then this keyword validates only if the instance is
less than or exactly equal to "maximum".
</t>
</section>
<section title="exclusiveMaximum">
<t>
The value of "exclusiveMaximum" MUST be number, representing an exclusive upper
limit for a numeric instance.
</t>
<t>
If the instance is a number, then the instance is valid only if it has a value
strictly less than (not equal to) "exclusiveMaximum".
</t>
</section>
<section title="minimum">
<t>
The value of "minimum" MUST be a number, representing an inclusive lower limit
for a numeric instance.
</t>
<t>
If the instance is a number, then this keyword validates only if the instance is
greater than or exactly equal to "minimum".
</t>
</section>
<section title="exclusiveMinimum">
<t>
The value of "exclusiveMinimum" MUST be number, representing an exclusive lower
limit for a numeric instance.
</t>
<t>
If the instance is a number, then the instance is valid only if it has a value
strictly greater than (not equal to) "exclusiveMinimum".
</t>
</section>
</section>
<section title="Validation Keywords for Strings" anchor="string">
<section title="maxLength">
<t>
The value of this keyword MUST be a non-negative integer.</t>
<t>
A string instance is valid against this keyword if its
length is less than, or equal to, the value of this keyword.
</t>
<t>
The length of a string instance is defined as the number of its
characters as defined by <xref target="RFC8259">RFC 8259</xref>.
</t>
</section>
<section title="minLength">
<t>
The value of this keyword MUST be a non-negative integer.
</t>
<t>
A string instance is valid against this keyword if its
length is greater than, or equal to, the value of this keyword.
</t>
<t>
The length of a string instance is defined as the number of its
characters as defined by <xref target="RFC8259">RFC 8259</xref>.
</t>
<t>
Omitting this keyword has the same behavior as a value of 0.
</t>
</section>
<section title="pattern" anchor="pattern">
<t>
The value of this keyword MUST be a string. This string SHOULD be a
valid regular expression, according to the ECMA 262 regular expression
dialect.
</t>
<t>
A string instance is considered valid if the regular
expression matches the instance successfully. Recall: regular
expressions are not implicitly anchored.
</t>
</section>
</section>
<section title="Validation Keywords for Arrays">
<section title="maxItems">
<t>
The value of this keyword MUST be a non-negative integer.
</t>
<t>
An array instance is valid against "maxItems" if its size is
less than, or equal to, the value of this keyword.
</t>
</section>
<section title="minItems">
<t>
The value of this keyword MUST be a non-negative integer.
</t>
<t>
An array instance is valid against "minItems" if its size is
greater than, or equal to, the value of this keyword.
</t>
<t>
Omitting this keyword has the same behavior as a value of 0.
</t>
</section>
<section title="uniqueItems">
<t>
The value of this keyword MUST be a boolean.
</t>
<t>
If this keyword has boolean value false, the instance validates
successfully. If it has boolean value true, the instance validates
successfully if all of its elements are unique.
</t>
<t>
Omitting this keyword has the same behavior as a value of false.
</t>
</section>
<section title="maxContains">
<t>
The value of this keyword MUST be a non-negative integer.
</t>
<t>
An array instance is valid against "maxContains" if the number of
elements that are valid against the schema for
<xref target="json-schema">"contains"</xref> is
less than, or equal to, the value of this keyword.
</t>
<t>
If "contains" is not present within the same schema object,
then this keyword has no effect.
</t>
</section>
<section title="minContains">
<t>
The value of this keyword MUST be a non-negative integer.
</t>
<t>
An array instance is valid against "minContains" if the number of
elements that are valid against the schema for
<xref target="json-schema">"contains"</xref> is
greater than, or equal to, the value of this keyword.
</t>
<t>
A value of 0 is allowed, but is only useful for setting a range
of occurrences from 0 to the value of "maxContains". A value of
0 with no "maxContains" causes "contains" to always pass validation.
</t>
<t>
If "contains" is not present within the same schema object,
then this keyword has no effect.
</t>
<t>
Omitting this keyword has the same behavior as a value of 1.
</t>
</section>
</section>
<section title="Validation Keywords for Objects">
<section title="maxProperties">
<t>
The value of this keyword MUST be a non-negative integer.
</t>
<t>
An object instance is valid against "maxProperties" if its
number of properties is less than, or equal to, the value of this
keyword.
</t>
</section>
<section title="minProperties">
<t>
The value of this keyword MUST be a non-negative integer.
</t>
<t>
An object instance is valid against "minProperties" if its
number of properties is greater than, or equal to, the value of this
keyword.
</t>
<t>
Omitting this keyword has the same behavior as a value of 0.
</t>
</section>
<section title="required">
<t>
The value of this keyword MUST be an array.
Elements of this array, if any, MUST be strings, and MUST be unique.
</t>
<t>
An object instance is valid against this keyword if every item in the array is
the name of a property in the instance.
</t>
<t>
Omitting this keyword has the same behavior as an empty array.
</t>
</section>
<section title="dependentRequired">
<t>
The value of this keyword MUST be an object. Properties in
this object, if any, MUST be arrays. Elements in each array,
if any, MUST be strings, and MUST be unique.
</t>
<t>
This keyword specifies properties that are required if a specific
other property is present. Their requirement is dependent on the
presence of the other property.
</t>
<t>
Validation succeeds if, for each name that appears in both
the instance and as a name within this keyword's value, every
item in the corresponding array is also the name of a property
in the instance.
</t>
<t>
Omitting this keyword has the same behavior as an empty object.
</t>
</section>
</section>
</section>
<section title='Semantic Validation With "format"' anchor="format">
<section title="Foreword">
<t>
Structural validation alone may be insufficient to validate that an instance
meets all the requirements of an application. The "format" keyword is defined to
allow interoperable semantic validation for a fixed subset of values which are
accurately described by authoritative resources, be they RFCs or other external
specifications.
</t>
<t>
The value of this keyword is called a format attribute. It MUST be a string. A
format attribute can generally only validate a given set of instance types. If
the type of the instance to validate is not in this set, validation for this
format attribute and instance SHOULD succeed.
</t>
</section>
<section title="Implementation Requirements">
<t>
The "format" keyword functions as both an annotation
and as an assertion. While no special effort is required to
implement it as an annotation conveying semantic meaning, implementing
validation is non-trivial.
</t>
<t>
Implementations MAY support the "format" keyword as a validation assertion.
Should they choose to do so:
<list>
<t>they SHOULD implement validation for attributes defined below;</t>
<t>they SHOULD offer an option to disable validation for this keyword.</t>
</list>
</t>
<t>
Implementations MAY add custom format attributes. Save for agreement between
parties, schema authors SHALL NOT expect a peer implementation to support this
keyword and/or custom format attributes.
</t>
</section>
<section title="Defined Formats">
<section title="Dates and Times">
<t>
These attributes apply to string instances.
</t>
<t>
Date and time format names are derived from
<xref target="RFC3339">RFC 3339, section 5.6</xref>.
</t>
<t>
Implementations supporting formats SHOULD implement support for
the following attributes:
<list style="hanging">
<t hangText="date-time:">
A string instance is valid against this attribute if it is
a valid representation according to the "date-time" production.
</t>
<t hangText="date:">
A string instance is valid against this attribute if it is
a valid representation according to the "full-date" production.
</t>
<t hangText="time:">
A string instance is valid against this attribute if it is
a valid representation according to the "full-time" production.
</t>
</list>
</t>
<t>
Implementations MAY support additional attributes using the other
production names defined in that section. If "full-date" or "full-time"
are implemented, the corresponding short form ("date" or "time"
respectively) MUST be implemented, and MUST behave identically.
Implementations SHOULD NOT define extension attributes
with any name matching an RFC 3339 production unless it validates
according to the rules of that production.
<cref>
There is not currently consensus on the need for supporting
all RFC 3339 formats, so this approach of reserving the
namespace will encourage experimentation without committing
to the entire set. Either the format implementation requirements
will become more flexible in general, or these will likely
either be promoted to fully specified attributes or dropped.
</cref>
</t>
</section>
<section title="Email Addresses">
<t>
These attributes apply to string instances.
</t>
<t>
A string instance is valid against these attributes if it is a valid
Internet email address as follows:
<list style="hanging">
<t hangText="email:">
As defined by <xref target="RFC5322">RFC 5322, section 3.4.1</xref>.
</t>
<t hangText="idn-email:">
As defined by <xref target="RFC6531">RFC 6531</xref>
</t>
</list>
Note that all strings valid against the "email" attribute are also
valid against the "idn-email" attribute.
</t>
</section>
<section title="Hostnames">
<t>
These attributes apply to string instances.
</t>
<t>
A string instance is valid against these attributes if it is a valid
representation for an Internet hostname as follows:
<list style="hanging">
<t hangText="hostname:">
As defined by <xref target="RFC1034">RFC 1034, section 3.1</xref>,
including host names produced using the Punycode algorithm
specified in <xref target="RFC5891">RFC 5891, section 4.4</xref>.
</t>
<t hangText="idn-hostname:">
As defined by either RFC 1034 as for hostname, or an
internationalized hostname as defined by
<xref target="RFC5890">RFC 5890, section 2.3.2.3</xref>.
</t>
</list>
Note that all strings valid against the "hostname" attribute are also
valid against the "idn-hostname" attribute.
</t>
</section>
<section title="IP Addresses">
<t>
These attributes apply to string instances.
</t>
<t>
A string instance is valid against these attributes if it is a valid
representation of an IP address as follows:
<list style="hanging">
<t hangText="ipv4:">
An IPv4 address according to the "dotted-quad" ABNF
syntax as defined in
<xref target="RFC2673">RFC 2673, section 3.2</xref>.
</t>
<t hangText="ipv6:">
An IPv6 address as defined in
<xref target="RFC4291">RFC 4291, section 2.2</xref>.
</t>
</list>
</t>
</section>
<section title="Resource Identifiers">
<t>
These attributes apply to string instances.
</t>
<t>
<list style="hanging">
<t hangText="uri:">
A string instance is valid against this attribute if it is
a valid URI, according to <xref target="RFC3986"/>.
</t>
<t hangText="uri-reference:">
A string instance is valid against this attribute if it is a valid URI
Reference (either a URI or a relative-reference),
according to <xref target="RFC3986"/>.
</t>
<t hangText="iri:">
A string instance is valid against this attribute if it is
a valid IRI, according to <xref target="RFC3987"/>.
</t>
<t hangText="iri-reference:">
A string instance is valid against this attribute if it is a valid IRI
Reference (either an IRI or a relative-reference),
according to <xref target="RFC3987"/>.
</t>
</list>
Note that all valid URIs are valid IRIs, and all valid URI References are
also valid IRI References.
</t>
</section>
<section title="uri-template">
<t>
This attribute applies to string instances.
</t>
<t>
A string instance is valid against this attribute if it is a valid URI Template
(of any level), according to <xref target="RFC6570"/>.
</t>
<t>
Note that URI Templates may be used for IRIs; there is no separate
IRI Template specification.
</t>
</section>
<section title="JSON Pointers">
<t>
These attributes apply to string instances.
</t>
<t>
<list style="hanging">
<t hangText="json-pointer:">
A string instance is valid against this attribute if it
is a valid JSON string representation of a JSON Pointer,
according to <xref target="RFC6901">RFC 6901, section 5</xref>.
</t>
<t hangText="relative-json-pointer:">
A string instance is valid against this attribute if it is a valid
<xref target="relative-json-pointer">Relative JSON Pointer</xref>.
</t>
</list>
To allow for both absolute and relative JSON Pointers, use "anyOf" or
"oneOf" to indicate support for either format.
</t>
</section>
<section title="regex">
<t>
This attribute applies to string instances.
</t>
<t>
A regular expression, which SHOULD be valid according to the
<xref target="ecma262">ECMA 262</xref> regular expression dialect.
</t>
<t>
Implementations that validate formats MUST accept at least the subset of
ECMA 262 defined in the <xref target="regexInterop">Regular Expressions</xref>
section of this specification, and SHOULD accept all valid ECMA 262 expressions.
</t>
</section>
</section>
</section>
<section title='String-Encoded Data' anchor="content">
<section title="Foreword">
<t>
Properties defined in this section indicate that an instance contains
non-JSON data encoded in a JSON string.
They describe the type of content and how it is encoded.
</t>
<t>
These properties provide additional information required to interpret JSON data
as rich multimedia documents.
</t>
</section>
<section title="Implementation Requirements">
<t>
The content keywords function as both annotations and as assertions.
While no special effort is required to implement them as annotations conveying
how applications can interpret the data in the string, implementing
validation of conformance to the media type and encoding is non-trivial.
</t>
<t>
Implementations MAY support the "contentMediaType" and "contentEncoding"
keywords as validation assertions.
Should they choose to do so, they SHOULD offer an option to disable validation
for these keywords.
</t>
</section>
<section title="contentEncoding">
<t>
If the instance value is a string, this property defines that the string
SHOULD be interpreted as binary data and decoded using the encoding
named by this property.
</t>
<t>
Possible values for this property are listed in
<xref target="RFC2045">RFC 2045, Sec 6.1</xref> and
<xref target="RFC4648">RFC 4648</xref>. For "base64", which is defined
in both RFCs, the definition in RFC 4648, which removes line length
limitations, SHOULD be used, as various other specifications have
mandated different lengths. Note that line lengths within a string
can be constrained using the <xref target="pattern">"pattern"</xref> keyword.
</t>
<t>
If this keyword is absent, but "contentMediaType" is present, this
indicates that the media type could be encoded into UTF-8 like any
other JSON string value, and does not require additional decoding.
</t>
<t>
The value of this property MUST be a string.
</t>
<t>
The value of this property SHOULD be ignored if the instance described is not a
string.
</t>
</section>
<section title="contentMediaType">
<t>
If the instance is a string, this property defines the media type
of the contents of the string. If "contentEncoding" is present,
this property describes the decoded string.
</t>
<t>
The value of this property MUST be a string, which MUST be a media type,
as defined by <xref target="RFC2046">RFC 2046</xref>.
</t>
<t>
The value of this property SHOULD be ignored if the instance described is not a
string.
</t>
</section>
<section title="contentSchema">
<t>
If the instance is a string, and if "contentMediaType" is present, this
property contains a schema which describes the structure of the string.
</t>
<t>
This keyword MAY be used with any media type that can be mapped into
JSON Schema's data model.
</t>
<t>
The value of this property SHOULD be ignored if the instance described is not a
string, or if "contentMediaType" is not present.
</t>
</section>
<section title="Example">
<figure>
<preamble>
Here is an example schema, illustrating the use of "contentEncoding" and
"contentMediaType":
</preamble>
<artwork>
<![CDATA[
{
"type": "string",
"contentEncoding": "base64",
"contentMediaType": "image/png"
}
]]>
</artwork>
<postamble>
Instances described by this schema should be strings, and their values
should be interpretable as base64-encoded PNG images.
</postamble>
</figure>
<figure>
<preamble>
Another example:
</preamble>
<artwork>
<![CDATA[
{
"type": "string",
"contentMediaType": "text/html"
}
]]>
</artwork>
<postamble>
Instances described by this schema should be strings containing HTML, using
whatever character set the JSON string was decoded into (default is
Unicode).
</postamble>
</figure>
<figure>
<preamble>
This example describes a JWT that is MACed using the HMAC SHA-256
algorithm, and requires the "iss" and "exp" fields in its claim set.
</preamble>
<artwork>
<![CDATA[
{
"type": "string",
"contentMediaType": "application/jwt",
"contentSchema": {
"type": "array",
"minItems": 2,
"items": [
{
"const": {
"typ": "JWT",
"alg": "HS256"
}
},
{
"type": "object",
"required": ["iss", "exp"],
"properties": {
"iss": {"type": "string"},
"exp": {"type": "integer"}
}
}
]
}
}]]>
</artwork>
<postamble>
Note that "contentEncoding" does not appear. While the "application/jwt"
media type makes use of base64url encoding, that is defined by the media
type, which determines how the JWT string is decoded into a list of two
JSON data structures: first the header, and then the payload. Since the
JWT media type ensures that the JWT can be represented in a JSON string,
there is no need for further encoding or decoding.
</postamble>
</figure>
</section>
</section>
<section title="Basic Meta-Data Annotations">
<t>
These general-purpose annotation keywords provide commonly used information
for documentation and user interface display purposes. They are not intended
to form a comprehensive set of features. Rather, additional vocabularies
can be defined for more complex annotation-based applications.
</t>
<section title='"title" and "description"'>
<t>
The value of both of these keywords MUST be a string.
</t>
<t>
Both of these keywords can be used to decorate a user interface with
information about the data produced by this user interface. A title will
preferably be short, whereas a description will provide explanation about
the purpose of the instance described by this schema.
</t>
</section>
<section title='"default"'>
<t>
There are no restrictions placed on the value of this keyword. When
multiple occurrences of this keyword are applicable to a single
sub-instance, implementations SHOULD remove duplicates.
</t>
<t>
This keyword can be used to supply a default JSON value associated with a
particular schema. It is RECOMMENDED that a default value be valid against
the associated schema.
</t>
</section>
<section title='"readOnly" and "writeOnly"'>
<t>
The value of these keywords MUST be a boolean. When multiple occurrences
of these keywords are applicable to a single sub-instance, the resulting
value MUST be true if any occurrence specifies a true value, and MUST
be false otherwise.
</t>
<t>
If "readOnly" has a value of boolean true, it indicates that the value
of the instance is managed exclusively by the owning authority, and
attempts by an application to modify the value of this property are
expected to be ignored or rejected by that owning authority.
</t>
<t>
An instance document that is marked as "readOnly for the entire document
MAY be ignored if sent to the owning authority, or MAY result in an
error, at the authority's discretion.
</t>
<t>
If "writeOnly" has a value of boolean true, it indicates that the value
is never present when the instance is retrieved from the owning authority.
It can be present when sent to the owning authority to update or create
the document (or the resource it represents), but it will not be included
in any updated or newly created version of the instance.
</t>
<t>
An instance document that is marked as "writeOnly" for the entire document
MAY be returned as a blank document of some sort, or MAY produce an error
upon retrieval, or have the retrieval request ignored, at the authority's
discretion.
</t>
<t>
For example, "readOnly" would be used to mark a database-generated serial
number as read-only, while "writeOnly" would be used to mark a password
input field.
</t>
<t>
These keywords can be used to assist in user interface instance generation.
In particular, an application MAY choose to use a widget that hides
input values as they are typed for write-only fields.
</t>
<t>
Omitting these keywords has the same behavior as values of false.
</t>
</section>
<section title='"examples"'>
<t>
The value of this keyword MUST be an array.
There are no restrictions placed on the values within the array.
When multiple occurrences of this keyword are applicable to a single
sub-instance, implementations MUST provide a flat array of all