RFC 6901
JavaScript Object Notation (JSON) Pointer
JavaScript Object Notation (JSON) Pointer π
RFC 6901, April 2013, Standards Track π Authors: Paul C. Bryan (editor) of Salesforce.com, Kris Zyp of SitePen (USA), and Mark Nottingham (editor) of Akamai ISSN: 2070-1721 This one doesn't obsolete or update any other RFCs, since the title block doesn't list any. π«Ά
Abstract β¨
okay so JSON Pointer gives you a string syntax for pointing at one specific value inside a JavaScript Object Notation (JSON) document. π¦
Status of This Memo π
This is an Internet Standards Track document. π₯
It's a product of the Internet Engineering Task Force (IETF), so it represents the consensus of the IETF community. It went through public review and got approved for publication by the Internet Engineering Steering Group (IESG). For more on Internet Standards, check Section 2 of RFC 5741. π
Info about the current status of this document, any errata, and how to send feedback is at http://www.rfc-editor.org/info/rfc6901. πΈ
Copyright Notice β
Copyright (c) 2013 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 (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, because they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions, and they are provided without warranty as described in the Simplified BSD License. π«Ά
Table of Contents π§
- 1. Introduction
- 2. Conventions
- 3. Syntax
- 4. Evaluation
- 5. JSON String Representation
- 6. URI Fragment Identifier Representation
- 7. Error Handling
- 8. Security Considerations
- 9. Acknowledgements
- 10. References
- 10.1. Normative References
- 10.2. Informative References
1. Introduction π
This spec defines JSON Pointer, which is a string syntax for identifying a specific value within a JavaScript Object Notation (JSON) document [RFC4627]. The whole point is that JSON Pointer is easy to write as a JSON string value, and it also works as a Uniform Resource Identifier (URI) [RFC3986] fragment identifier. It's giving versatile. π
2. Conventions π
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 [RFC2119]. π
This spec writes its normative syntax rules in Augmented Backus-Naur Form (ABNF) [RFC5234] notation. π
3. Syntax π¦
A JSON Pointer is a Unicode string (see [RFC4627], Section 3) that holds a sequence of zero or more reference tokens. Each token is prefixed by a / (%x2F) character. π
The characters ~ (%x7E) and / (%x2F) have special meanings in JSON Pointer, so ~ needs to be encoded as ~0, and / needs to be encoded as ~1 when those characters show up in a reference token. Lowkey important! π
Here's the ABNF syntax of a JSON Pointer:
json-pointer = *( "/" reference-token )
reference-token = *( unescaped / escaped )
unescaped = %x00-2E / %x30-7D / %x7F-10FFFF
; %x2F ('/') and %x7E ('~') are excluded from 'unescaped'
escaped = "~" ( "0" / "1" )
; representing '~' and '/', respectively
If a JSON Pointer value doesn't conform to this syntax, that's an error condition (see Section 7). π
Also, JSON Pointers are specified in characters, not bytes. π
4. Evaluation π₯
Evaluation of a JSON Pointer starts with a reference to the root value of a JSON document, and it finishes with a reference to some value within that document. Each reference token in the JSON Pointer gets evaluated in order, one at a time. β¨
Evaluation of each reference token starts by decoding any escaped character sequence. You do this by first changing every occurrence of ~1 into /, and then changing every occurrence of ~0 into ~. Doing the substitutions in this order means an implementation avoids the mistake of turning ~01 into ~1 first and then into /, which would be wrong. The string ~01 correctly becomes ~1 after transformation. π§
Then the reference token changes which value gets referenced, following this scheme:
- If the currently referenced value is a JSON object, the new referenced value is the object member whose name matches the reference token. A member name equals the token if it has the same number of Unicode characters as the token and their code points are byte-by-byte equal. No Unicode character normalization is performed. If a referenced member name isn't unique in an object, the member being referenced is undefined, and evaluation fails (see below). π
- If the currently referenced value is a JSON array, the reference token MUST contain either:
- characters made of digits (see ABNF below; note that leading zeros are not allowed) that represent an unsigned base-10 integer value, which makes the new referenced value the array element with the zero-based index identified by the token, or
- exactly the single character "-", which makes the new referenced value the (nonexistent) member after the last array element.
The ABNF syntax for array indices is:
array-index = %x30 / ( %x31-39 *(%x30-39) )
; "0", or digits without a leading "0"
Implementations evaluate each reference token against the document's contents, and they'll raise an error condition if they fail to resolve a concrete value for any of the JSON pointer's reference tokens. For example, if an array gets referenced with a non-numeric token, an error condition gets raised. See Section 7 for details. πΈ
Heads up: using - to index an array will always cause such an error condition, because by definition it refers to a nonexistent array element. So applications of JSON Pointer need to say how that character gets handled if it's going to be useful. π
Any error condition that the JSON Pointer application doesn't define a specific action for results in termination of evaluation. π
5. JSON String Representation π
A JSON Pointer can be represented in a JSON string value. Per [RFC4627], Section 2.5, all instances of quotation mark " (%x22), reverse solidus \ (%x5C), and control (%x00-1F) characters MUST be escaped. π
Before you process a JSON string as a JSON Pointer, you have to unescape any backslash escape sequences. π¦
Here's an example JSON document:
{
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
}
These JSON strings evaluate to the values next to them:
"" // the whole document
"/foo" ["bar", "baz"]
"/foo/0" "bar"
"/" 0
"/a~1b" 1
"/c%d" 2
"/e^f" 3
"/g|h" 4
"/i\\j" 5
"/k\"l" 6
"/ " 7
"/m~0n" 8
6. URI Fragment Identifier Representation π§
A JSON Pointer can be represented in a URI fragment identifier. You encode it into octets using UTF-8 [RFC3629], and you percent-encode any characters that the fragment rule in [RFC3986] doesn't allow. π
Also, a given media type has to specify JSON Pointer as its fragment identifier syntax explicitly (usually in its registration [RFC6838]). Just because a document is JSON doesn't mean JSON Pointer can be used as its fragment identifier syntax. In particular, the fragment identifier syntax for application/json is not JSON Pointer. π
Quick reminder: being JSON doesn't automatically make a document JSON Pointer friendly. Check the media type's registration first. π
Using the same example document as above, these URI fragment identifiers evaluate to the values next to them:
# // the whole document
#/foo ["bar", "baz"]
#/foo/0 "bar"
#/ 0
#/a~1b 1
#/c%25d 2
#/e%5Ef 3
#/g%7Ch 4
#/i%5Cj 5
#/k%22l 6
#/%20 7
#/m~0n 8
7. Error Handling π¨
When an error condition happens, evaluation of the JSON Pointer fails to complete. π
Error conditions include, but aren't limited to:
- Invalid pointer syntax
- A pointer that references a nonexistent value
This spec doesn't define how errors get handled. An application of JSON Pointer SHOULD specify the impact and handling of each type of error. π
For example, some applications might stop pointer processing when they hit an error, while others may try to recover from missing values by inserting default ones. π¦
8. Security Considerations π
A JSON Pointer isn't guaranteed to reference an actual JSON value. That's the big danger here! So applications that use JSON Pointer should plan for this situation by defining how a pointer that doesn't resolve ought to be handled. π
Also, JSON pointers can contain the NUL (Unicode U+0000) character. Be careful not to misread this character in programming languages that use NUL to mark the end of a string. Seriously, this one has bitten people. π
9. Acknowledgements π«Ά
Huge thanks to these individuals, who contributed ideas, feedback, and wording to this specification: Mike Acar, Carsten Bormann, Tim Bray, Jacob Davies, Martin J. Duerst, Bjoern Hoehrmann, James H. Manger, Drew Perttula, and Julian Reschke. π
10. References π
10.1. Normative References
- [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997.
- [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 10646", STD 63, RFC 3629, November 2003.
- [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform Resource Identifier (URI): Generic Syntax", STD 66, RFC 3986, January 2005.
- [RFC4627] Crockford, D., "The application/json Media Type for JavaScript Object Notation (JSON)", RFC 4627, July 2006.
- [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax Specifications: ABNF", STD 68, RFC 5234, January 2008.
10.2. Informative References
- [RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type Specifications and Registration Procedures", BCP 13, RFC 6838, January 2013.
Authors' Addresses π
Paul C. Bryan (editor) Salesforce.com Phone: +1 604 783 1481 EMail: pbryan@anode.ca
Kris Zyp SitePen (USA) Phone: +1 650 968 8787 EMail: kris@sitepen.com
Mark Nottingham (editor) Akamai EMail: mnot@mnot.net
π¦ where this page comes from
- ietf: rfc6901 2013-04
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms