forked from json-schema-org/json-schema-spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelative-json-pointer.xml
331 lines (312 loc) · 13.7 KB
/
relative-json-pointer.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
<?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 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-relative-json-pointer-02" ipr="trust200902">
<front>
<title abbrev="Relative JSON Pointers">Relative JSON Pointers</title>
<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>
<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>
<date year="2018"/>
<workgroup>Internet Engineering Task Force</workgroup>
<keyword>JSON</keyword>
<keyword>JavaScript</keyword>
<keyword>Object</keyword>
<keyword>Notation</keyword>
<abstract>
<t>
JSON Pointer is a syntax for specifying locations in a JSON document,
starting from the document root. This document defines an extension
to the JSON Pointer syntax, allowing relative locations from within
the document.
</t>
</abstract>
</front>
<middle>
<section title="Introduction">
<t>
JSON Pointer (<xref target="RFC6901">RFC 6901</xref>) is a syntax for specifying
locations in a JSON document, starting from the document root. This
document defines a related syntax allowing identification of relative locations
from within the document.
</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>
</section>
<section title="Syntax">
<t>
A Relative JSON Pointer is a Unicode string in UTF-8 encoding (see RFC 8259,
<xref target="RFC8259">Section 8</xref>), comprising a non-negative integer,
followed by either a '#' (%x23) character or a JSON Pointer
(<xref target="RFC6901">RFC 6901</xref>).
</t>
<t>
The separation between the integer prefix and the JSON Pointer will
always be unambiguous, because a JSON Pointer must be either zero-
length or start with a '/' (%x2F). Similarly, a JSON Pointer will
never be ambiguous with the '#'.
</t>
<figure align="center">
<preamble>
The ABNF syntax of a Relative JSON Pointer is:
</preamble>
<artwork>
<![CDATA[
relative-json-pointer = non-negative-integer <json-pointer>
relative-json-pointer =/ non-negative-integer "#"
non-negative-integer = %x30 / %x31-39 *( %x30-39 )
; "0", or digits without a leading "0"
]]>
</artwork>
<postamble>
where <json-pointer> follows the production defined in
<xref target="RFC6901">RFC 6901, Section 3</xref> ("Syntax").
</postamble>
</figure>
<t>
</t>
</section>
<section title="Evaluation">
<t>
Evaluation of a Relative JSON Pointer begins with a reference to a
value within a JSON document, and completes with either a value
within that document, a string corresponding to an object member, or
integer value representing an array index.
</t>
<t>
Evaluation begins by processing the non-negative-integer prefix.
This can be found by taking the longest continuous sequence of decimal
digits available, starting from the beginning of the string, taking
the decimal numerical value. If this value is more than zero, then
the following steps are repeated that number of times:
<list>
<t>
If the current referenced value is the root of the document, then
evaluation fails (see below).
</t>
<t>
If the referenced value is an item within an array, then the new
referenced value is that array.
</t>
<t>
If the referenced value is an object member within an object, then
the new referenced value is that object.
</t>
</list>
If the remainder of the Relative JSON Pointer is a JSON Pointer, then
evaluation proceeds as per <xref target="RFC6901">RFC 6901, Section 4</xref>
("Evaluation"), with the modification that the initial reference
being used is the reference currently being held (which may not be
root of the document).
</t>
<t>
Otherwise (when the remainder of the Relative JSON Pointer is the
character '#'), the final result is determined as follows:
<list>
<t>
If the current referenced value is the root of the document, then
evaluation fails (see below).
</t>
<t>
If the referenced value is an item within an array, then the final
evaluation result is the value's index position within the array.
</t>
<t>
If the referenced value is an object member within an object, then
the new referenced value is the corresponding member name.
</t>
</list>
</t>
</section>
<section title="JSON String Representation">
<t>
The concerns surrounding JSON String representation of a Relative
JSON Pointer are identical to those laid out in
<xref target="RFC6901">RFC 6901, Section 5</xref>.
</t>
<section title="Examples">
<figure align="center">
<preamble>
For example, given the JSON document:
</preamble>
<artwork>
<![CDATA[
{
"foo": ["bar", "baz"],
"highly": {
"nested": {
"objects": true
}
}
}
]]>
</artwork>
</figure>
<figure align="center">
<preamble>
Starting from the value "baz" (inside "foo"), the following JSON
strings evaluate to the accompanying values:
</preamble>
<artwork>
<![CDATA[
"0" "baz"
"1/0" "bar"
"2/highly/nested/objects" true
"0#" 1
"1#" "foo"
]]>
</artwork>
</figure>
<figure align="center">
<preamble>
Starting from the value {"objects":true} (corresponding to the member
key "nested"), the following JSON strings evaluate to the
accompanying values:
</preamble>
<artwork>
<![CDATA[
"0/objects" true
"1/nested/objects" true
"2/foo/0" "bar"
"0#" "nested"
"1#" "highly"
]]>
</artwork>
</figure>
</section>
</section>
<section title="Non-use in URI Fragment Identifiers">
<t>
Unlike a JSON Pointer, a Relative JSON Pointer can not be used in a
URI fragment identifier. Such fragments specify exact positions
within a document, and therefore Relative JSON Pointers are not
suitable.
</t>
</section>
<section title="Error Handling">
<t>
In the event of an error condition, evaluation of the JSON Pointer
fails to complete.
</t>
<t>
Evaluation may fail due to invalid syntax, or referencing a non-
existent value. This specification does not define how errors are
handled. An application of JSON Relative Pointer SHOULD specify the
impact and handling of each type of error.
</t>
</section>
<section title="Relationship to JSON Pointer">
<t>
Relative JSON Pointers are intended as a companion to JSON Pointers.
Applications MUST specify the use of each syntax separately.
Defining either JSON Pointer or Relative JSON Pointer as an acceptable
syntax does not imply that the other syntax is also acceptable.
</t>
</section>
<section title="Acknowledgements">
<t>
The language and structure of this specification are based heavily on
<xref target="RFC6901"/>, sometimes quoting it outright.
</t>
<t>
This draft remains primarily as written and published by Geraint Luff,
with only minor subsequent alterations under new editorship.
</t>
</section>
<section title="Security Considerations">
<t>
Evaluation of a given Relative JSON Pointer is not guaranteed to
reference an actual JSON value. Applications using Relative JSON
Pointer should anticipate this situation by defining how a pointer
that does not resolve ought to be handled.
</t>
<t>
As part of processing, a composite data structure may be assembled
from multiple JSON documents (in part or in full). In such cases,
applications SHOULD ensure that a Relative JSON Pointer does not
evaluate to a value outside the document for which is was written.
</t>
<t>
Note that JSON pointers can contain the NUL (Unicode U+0000)
character. Care is needed not to misinterpret this character in
programming languages that use NUL to mark the end of a string.
</t>
</section>
</middle>
<back>
<!-- References Section -->
<references title="Normative References">
&RFC2119;
&RFC6901;
</references>
<references title="Informative References">
&RFC8259;
</references>
<section title="ChangeLog">
<t>
<cref>This section to be removed before leaving Internet-Draft status.</cref>
</t>
<t>
<list style="hanging">
<t hangText="draft-handrews-relative-json-pointer-02">
<list style="symbols">
<t>Update to the latest JSON RFC</t>
</list>
</t>
<t hangText="draft-handrews-relative-json-pointer-01">
<list style="symbols">
<t>The initial number is "non-negative", not "positive"</t>
</list>
</t>
<t hangText="draft-handrews-relative-json-pointer-00">
<list style="symbols">
<t>Revived draft with identical wording and structure.</t>
<t>Clarified how to use alongside JSON Pointer.</t>
</list>
</t>
<t hangText="draft-luff-relative-json-pointer-00">
<list style="symbols">
<t>Initial draft.</t>
</list>
</t>
</list>
</t>
</section>
</back>
</rfc>