Internet-Draft | Relative JSON Pointers | June 2023 |
Luff, et al. | Expires 21 December 2023 | [Page] |
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.¶
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.¶
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.¶
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."¶
This Internet-Draft will expire on 21 December 2023.¶
Copyright (c) 2023 IETF Trust and the persons identified as the document authors. All rights reserved.¶
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Revised BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Revised BSD License.¶
JSON Pointer (RFC 6901 [RFC6901]) 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.¶
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 RFC 2119 [RFC2119].¶
A Relative JSON Pointer is a Unicode string in UTF-8 encoding (see RFC 8259, Section 8 [RFC8259]), comprising a non-negative integer, an optional index adjustment consisting of '+' (%x2B) or '-' (%x2D) followed by a positive integer, followed by either a '#' (%x23) character or a JSON Pointer (RFC 6901 [RFC6901]).¶
The separation between the integer prefix (with optional adjustment) 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 '#'.¶
The ABNF syntax of a Relative JSON Pointer is:¶
relative-json-pointer = origin-specification ( "#" / json-pointer ) ; json-pointer from RFC 6901 origin-specification = non-negative-integer [ index-manipulation ] index-manipulation = ( "+" / "-" ) positive-integer non-negative-integer = "0" / positive-integer positive-integer = %x31-39 *DIGIT ; digits without a leading zero¶
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.¶
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 the value is zero, the following steps are skipped. If this value is more than zero, then the following steps are repeated that number of times:¶
If the next character is a plus ("+") or minus ("-"), followed by another continuous sequence of decimal digits, the following steps are taken using the decimal numeric value of that plus or minus sign and decimal sequence:¶
If the remainder of the Relative JSON Pointer is a JSON Pointer, then evaluation proceeds as per RFC 6901, Section 5 [RFC6901] with the modification that the initial reference being used is the reference currently being held (which may not be root of the document).¶
Otherwise (when the remainder of the Relative JSON Pointer is the character '#'), the final result is determined as follows:¶
The concerns surrounding JSON String representation of a Relative JSON Pointer are identical to those laid out in RFC 6901, Section 5 [RFC6901].¶
For example, given the JSON document:¶
{ "foo": ["bar", "baz", "biz"], "highly": { "nested": { "objects": true } } }¶
Starting from the value "baz" (inside "foo"), the following JSON strings evaluate to the accompanying values:¶
"0" "baz" "1/0" "bar" "0-1" "bar" "2/highly/nested/objects" true "0#" 1 "0+1#" 2 "1#" "foo"¶
Starting from the value {"objects":true} (corresponding to the member key "nested"), the following JSON strings evaluate to the accompanying values:¶
"0/objects" true "1/nested/objects" true "2/foo/0" "bar" "0#" "nested" "1#" "highly"¶
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.¶
In the event of an error condition, evaluation of the JSON Pointer fails to complete.¶
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.¶
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.¶
The language and structure of this specification are based heavily on [RFC6901], sometimes quoting it outright.¶
This draft remains primarily as written and published by Geraint Luff, with only minor subsequent alterations under new editorship.¶
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.¶
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.¶
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.¶
This document has no IANA actions.¶
This section to be removed before leaving Internet-Draft status.¶