[Docs] [txt|pdf|xml|html] [Tracker] [WG] [Email] [Diff1] [Diff2] [Nits]

Versions: (draft-pbryan-zyp-json-pointer) 00 01 02 03 04 05 06 07 08 09 RFC 6901

Applications Area Working Group                            P. Bryan, Ed.
Internet-Draft                                            Salesforce.com
Intended status: Informational                                    K. Zyp
Expires: April 25, 2013                                    SitePen (USA)
                                                      M. Nottingham, Ed.
                                                        October 22, 2012


                              JSON Pointer
                   draft-ietf-appsawg-json-pointer-05

Abstract

   JSON Pointer defines a string syntax for identifying a specific value
   within a JSON document.

Status of this Memo

   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 http://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 April 25, 2013.

Copyright Notice

   Copyright (c) 2012 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, as 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 are provided without warranty as
   described in the Simplified BSD License.




Bryan, et al.            Expires April 25, 2013                 [Page 1]

Internet-Draft                JSON Pointer                  October 2012


Table of Contents

   1.  Introduction  . . . . . . . . . . . . . . . . . . . . . . . . . 3
   2.  Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . 3
   3.  Syntax  . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
   4.  Evaluation  . . . . . . . . . . . . . . . . . . . . . . . . . . 3
   5.  JSON String Representation  . . . . . . . . . . . . . . . . . . 4
   6.  URI Fragment Identifier Representation  . . . . . . . . . . . . 5
   7.  Error Handling  . . . . . . . . . . . . . . . . . . . . . . . . 6
   8.  IANA Considerations . . . . . . . . . . . . . . . . . . . . . . 6
   9.  Security Considerations . . . . . . . . . . . . . . . . . . . . 6
   10. Acknowledgements  . . . . . . . . . . . . . . . . . . . . . . . 7
   11. References  . . . . . . . . . . . . . . . . . . . . . . . . . . 7
     11.1.  Normative References . . . . . . . . . . . . . . . . . . . 7
     11.2.  Informative References . . . . . . . . . . . . . . . . . . 7
   Authors' Addresses  . . . . . . . . . . . . . . . . . . . . . . . . 7



































Bryan, et al.            Expires April 25, 2013                 [Page 2]

Internet-Draft                JSON Pointer                  October 2012


1.  Introduction

   This specification defines JSON Pointer, a string syntax for
   identifying a specific value within a JavaScript Object Notation
   (JSON) [RFC4627] document.  It is intended to be easily expressed in
   JSON string values as well as Uniform Resource Identifier (URI)
   [RFC3986] fragment identifiers.


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 specification expresses normative syntax rules using Augmented
   Backus-Naur Form (ABNF) [RFC5234] notation.


3.  Syntax

   A JSON Pointer is a [Unicode] string containing a sequence of zero or
   more reference tokens, each prefixed by a '/' (%x2F) character.

   Since the characters '~' (%x7E) and '/' (%x2F) have a special meaning
   in JSON Pointer, they need to be encoded as '~0' and '~1'
   respectively, when appearing in a reference token.

   Its ABNF syntax is:

   json-pointer = *( "/" reference-token )
   reference-token = *( unescaped / escaped )
   unescaped = %x00-2E / %x30-7D / %x7F-10FFFF
   escaped = "~" ( "0" / "1" )

   It is an error condition if a JSON Pointer value does not conform to
   this syntax (see Section 7).


4.  Evaluation

   Evaluation of a JSON Pointer begins with a reference to the root
   value of a JSON document and completes with a reference to some value
   within the document.  Each reference token in the JSON Pointer is
   sequentially evaluated.

   Evaluation of each reference token begins by decoding any escaped
   character sequence; this is performed by first transforming any



Bryan, et al.            Expires April 25, 2013                 [Page 3]

Internet-Draft                JSON Pointer                  October 2012


   occurrence of the sequence '~1' to '/', then transforming any
   occurrence of the sequence '~0' to '~'.

   The reference token then modifies which value is referenced according
   to the following scheme:

   o  If the currently referenced value is a JSON object, the new
      referenced value is the object member with the name identified by
      the reference token.  The member name is equal to the token if it
      has the same number of Unicode characters as token and their code
      points are position-wise equal.  If a referenced member name is
      not unique in an object, the member that is referenced is
      undefined, and evaluation fails (see below).

   o  If the currently referenced value is a JSON array, the reference
      token MUST contain either:

      *  characters that represent an unsigned base-10 integer value
         (possibly with leading zeros), making the new referenced value
         is the array element with the zero-based index identified by
         the token, or

      *  exactly the single character "-", making the new referenced
         value the (non-existant) member after the last array element.

   If a reference token is being evaluated against a JSON document,
   implementations will evaluate each token against the document's
   contents, and terminate evaluation with an error condition if it
   fails to resolve a concrete value for any of the JSON pointer's
   reference tokens.  See Section 7 for details.

   Note that the use of the "-" character to index an array will always
   result in such an error; applications of JSON Pointer thus need to
   specify how it is to be handled, if it is to be useful.


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.

   Note that before processing a JSON string as a JSON Pointer,
   backslash escape sequences must be unescaped.

   For example, given the JSON document




Bryan, et al.            Expires April 25, 2013                 [Page 4]

Internet-Draft                JSON Pointer                  October 2012


   {
      "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
   }

   Then the following JSON strings evaluate to the accompanying values:


    ""         // 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 by
   encoding it into octets, using UTF-8 [RFC3629], percent-encoding
   those characters not allowed by the fragment rule in [RFC3986].

   Note that a given media type needs to nominate JSON Pointer as its
   fragment identifier syntax explicitly (usually, in its registration
   [RFC4288]); i.e., just because a document is JSON does not imply that
   JSON Pointer can be used as its fragment identifier syntax.  In
   particular, the fragment identifier syntax for application/json is
   not JSON Pointer.

   Given the same example document as above, the following URI fragment
   identifiers evaluate to the accompanying values:






Bryan, et al.            Expires April 25, 2013                 [Page 5]

Internet-Draft                JSON Pointer                  October 2012


    #                  // 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

   In the event of an error condition, evaluation of the JSON Pointer
   fails to complete.

   This includes, but is not limited to:

   o  Invalid pointer syntax

   o  A pointer that references a non-existent value

   This specification does not define how errors are 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 upon an
   error; others may attempt to recover from missing values by inserting
   default ones.


8.  IANA Considerations

   This document has no impact upon IANA.


9.  Security Considerations

   A given JSON Pointer is not guaranteed to reference an actual JSON
   value.  Implementations should be aware of this and take appropriate
   precautions.

   Note that JSON pointers can contain the NUL (Unicode U+0000)
   character, which may not be representable in all programming
   languages.



Bryan, et al.            Expires April 25, 2013                 [Page 6]

Internet-Draft                JSON Pointer                  October 2012


10.  Acknowledgements

   The following individuals 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, Julian
      Reschke.


11.  References

11.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.

   [Unicode]  The Unicode Consortium, "The Unicode Standard, Version
              6.0", October 2011,
              <http://www.unicode.org/versions/Unicode6.0.0/>.

11.2.  Informative References

   [RFC4288]  Freed, N. and J. Klensin, "Media Type Specifications and
              Registration Procedures", BCP 13, RFC 4288, December 2005.


Authors' Addresses

   Paul C. Bryan (editor)
   Salesforce.com

   Phone: +1 604 783 1481
   Email: pbryan@anode.ca




Bryan, et al.            Expires April 25, 2013                 [Page 7]

Internet-Draft                JSON Pointer                  October 2012


   Kris Zyp
   SitePen (USA)

   Phone: +1 650 968 8787
   Email: kris@sitepen.com


   Mark Nottingham (editor)

   Email: mnot@mnot.net









































Bryan, et al.            Expires April 25, 2013                 [Page 8]


Html markup produced by rfcmarkup 1.109, available from https://tools.ietf.org/tools/rfcmarkup/