[Docs] [txt|pdf|xml|html] [Tracker] [Email] [Nits]

Versions: 00 01 02 03 04 draft-ietf-appsawg-json-patch

Internet Engineering Task Force                            P. Bryan, Ed.
Internet-Draft                                        ForgeRock US, Inc.
Intended status: Informational                            April 20, 2011
Expires: October 22, 2011


A JSON Media Type for Describing Partial Modifications to JSON Documents
                       draft-pbryan-json-patch-00

Abstract

   JSON (JavaScript Object Notation) Patch defines the media type
   "application/patch+json", a JSON-based document structure for
   specifying partial modifications to apply to 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 October 22, 2011.

Copyright Notice

   Copyright (c) 2011 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                   Expires October 22, 2011                [Page 1]

Internet-Draft            JSON Patch Media Type               April 2011


Table of Contents

   1.  Introduction  . . . . . . . . . . . . . . . . . . . . . . . . . 3
   2.  Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . 3
   3.  Patch Object Structure  . . . . . . . . . . . . . . . . . . . . 3
     3.1.  patches . . . . . . . . . . . . . . . . . . . . . . . . . . 3
     3.2.  op  . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
     3.3.  path  . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
     3.4.  element . . . . . . . . . . . . . . . . . . . . . . . . . . 4
     3.5.  value . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
   4.  Patch Operations  . . . . . . . . . . . . . . . . . . . . . . . 4
     4.1.  add . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
     4.2.  remove  . . . . . . . . . . . . . . . . . . . . . . . . . . 4
   5.  Error Handling  . . . . . . . . . . . . . . . . . . . . . . . . 5
   6.  Acknowledgements  . . . . . . . . . . . . . . . . . . . . . . . 5
   7.  IANA Considerations . . . . . . . . . . . . . . . . . . . . . . 5
   8.  Security Considerations . . . . . . . . . . . . . . . . . . . . 5
   9.  References  . . . . . . . . . . . . . . . . . . . . . . . . . . 6
     9.1.  Normative References  . . . . . . . . . . . . . . . . . . . 6
     9.2.  Informative References  . . . . . . . . . . . . . . . . . . 6
   Appendix A.  Examples . . . . . . . . . . . . . . . . . . . . . . . 6
     A.1.  Adding an Object Property . . . . . . . . . . . . . . . . . 6
     A.2.  Adding an Array Element . . . . . . . . . . . . . . . . . . 7
     A.3.  Removing an Object Property . . . . . . . . . . . . . . . . 7
     A.4.  Removing an Array Element . . . . . . . . . . . . . . . . . 8
     A.5.  Replacing a Value . . . . . . . . . . . . . . . . . . . . . 8
   Appendix B.  Changelog  . . . . . . . . . . . . . . . . . . . . . . 9
   Appendix C.  Open Issues  . . . . . . . . . . . . . . . . . . . . . 9
   Author's Address  . . . . . . . . . . . . . . . . . . . . . . . . . 9






















Bryan                   Expires October 22, 2011                [Page 2]

Internet-Draft            JSON Patch Media Type               April 2011


1.  Introduction

   JavaScript Object Notation (JSON) [RFC4627] has become a popular
   format for the storage and transmission of structured data between
   systems.  As a result, numerous web service APIs support the JSON
   media type.  The HTTP PATCH [RFC5789] specification extends HTTP with
   a new method to perform partial modifications to resources.

   This Internet-Draft proposes the JSON-Patch media type "application/
   patch+json", a JSON-based document structure for specifying partial
   modifications to apply to a JSON document.


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 RFC 2119 [RFC2119].


3.  Patch Object Structure

   A JSON-Patch document is a JSON document that contains an object
   which specifies the set of operations to apply to a target JSON
   document.

   An example JSON-Patch document:

   {
     "patches": [
       { "op": "remove", "path": "$.a.b.c" },
       { "op": "add", "path": "$.a.b", "element": "c", "value": "foo" }
     ]
   }

3.1.  patches

   An array of objects; each object specifies a single patch operation
   to be applied to the target JSON document.  Patch operations MUST be
   applied sequentially in the order they appear in the array.  After
   the first patch has been applied, the resulting JSON document becomes
   the target for the next patch operation.  This process repeats until
   all patches have been applied.

3.2.  op

   MUST be a string value.  Specifies the patch operation to be applied.
   Defined patch operations are "add" and "remove".



Bryan                   Expires October 22, 2011                [Page 3]

Internet-Draft            JSON Patch Media Type               April 2011


3.3.  path

   MUST be a string value.  Contains a concrete [JSONPath] expression
   (i.e.  MUST contain only the root $, object property . [] and array
   subscript [] operators).  It is an error condition if a path resolves
   to anything but a single node within the target JSON document.

3.4.  element

   MUST be a string or integer value.  Specifies the child node to add
   into the node specified by the path.  If string, specifies an object
   property to insert; if integer, specifies an array index to insert
   at.  It is an error condition if the specified node type is
   incompatible with the "element" value (i.e. object with integer
   element, array with string element).

3.5.  value

   The value to insert into the specified node.


4.  Patch Operations

   The patch operations are "add" and "remove".

4.1.  add

   Adds a new property into an object or element into an array.

   If adding a property into an object, the "element" specifies the
   property to be added.  It is an error condition if the property
   already exists in the object.

   If adding into an array, the "element" specifies the index where the
   value should be inserted.  Any elements at or above the specified
   index are shifted one position to the right (i.e. indexes are
   incremented).  It is an error condition if an addition would result
   in sparse allocation of array element(s).

4.2.  remove

   Removes the node specified by the path.  It is an error condition if
   the node to be removed does not exist.

   If removing an element from an array, any elements above the
   specified index are shifted one position to the left (i.e. indexes
   are decremented).




Bryan                   Expires October 22, 2011                [Page 4]

Internet-Draft            JSON Patch Media Type               April 2011


5.  Error Handling

   In the event of an error condition, whether patch processing ceases,
   and/or how error conditions are communicated and handled are left to
   the implementation to specify.

   Enforcing safety and/or idempotency of a JSON patch document is
   specified and handled by the implementation, based-on any mechanisms
   in other related specifications, such as HTTP [RFC2616] and HTTP
   PATCH [RFC5789].


6.  Acknowledgements

   The structure of a JSON patch document was informed by the XML Patch
   document [RFC5261] specification.


7.  IANA Considerations

   The proposed MIME media type for the JSON patch document is
   "application/patch+json".

   Type name: application

   Subtype name: patch+json

   Required parameters: none

   Optional parameters: none


8.  Security Considerations

   This specification is based-on the JSON format, therefore has the
   same security considerations as [RFC4627].

   This specification uses [JSONPath] expressions to resolve the nodes
   to be modified.  Such expressions should not be evaluated directly by
   the implementation language interpreter due to the potential for
   injection of malicious code.


9.  References







Bryan                   Expires October 22, 2011                [Page 5]

Internet-Draft            JSON Patch Media Type               April 2011


9.1.  Normative References

   [RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
              Requirement Levels", BCP 14, RFC 2119, March 1997.

   [RFC4627]  Crockford, D., "The application/json Media Type for
              JavaScript Object Notation (JSON)", RFC 4627, July 2006.

9.2.  Informative References

   [JSONPath]
              Goessner, S., "JSONPath: XPath for JSON", April 2007,
              <http://goessner.net/articles/JsonPath/>.

   [RFC2616]  Fielding, R., Gettys, J., Mogul, J., Frystyk, H.,
              Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext
              Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999.

   [RFC5261]  Urpalainen, J., "An Extensible Markup Language (XML) Patch
              Operations Framework Utilizing XML Path Language (XPath)
              Selectors", RFC 5261, September 2008.

   [RFC5789]  Dusseault, L. and J. Snell, "PATCH Method for HTTP",
              RFC 5789, March 2010.


Appendix A.  Examples

A.1.  Adding an Object Property

   An example target JSON document:

   {
     "foo": "bar"
   }

   A JSON patch document:

   {
     "patches": [
       { "op": "add", "path": "$", "element": "baz", "value": "qux" }
     ]
   }

   The resulting JSON document:






Bryan                   Expires October 22, 2011                [Page 6]

Internet-Draft            JSON Patch Media Type               April 2011


   {
     "baz": "qux",
     "foo": "bar"
   }

A.2.  Adding an Array Element

   An example target JSON document:

   {
     "foo": ["bar", "baz"]
   }

   A JSON patch document:

   {
     "patches": [
       { "op": "add", "path": "$.foo", "element": 1, "value": "qux" }
     ]
   }

   The resulting JSON document:

   {
     "foo": [ "bar", "qux", "baz" ]
   }

A.3.  Removing an Object Property

   An example target JSON document:

   {
     "baz": "qux",
     "foo": "bar"
   }

   A JSON patch document:

   {
     "patches": [
       { "op": "remove", "path": "$.baz" }
     ]
   }

   The resulting JSON document:

   {
     "foo": "bar"



Bryan                   Expires October 22, 2011                [Page 7]

Internet-Draft            JSON Patch Media Type               April 2011


   }

A.4.  Removing an Array Element

   An example target JSON document:

   {
     "foo": [ "bar", "qux", "baz" ]
   }

   A JSON patch document:

   {
     "patches": [
       { "op": "remove", "path": "$.foo[1]" }
     ]
   }

   The resulting JSON document:

   {
     "foo": ["bar", "baz"]
   }

A.5.  Replacing a Value

   Replacing a value is performed by removing a value and inserting it.

   An example target JSON document:

   {
     "baz": "qux",
     "foo": "bar"
   }

   A JSON patch document:

   {
     "patches": [
       { "op": "remove", "path": "$.baz" },
       { "op": "add", "path": "$", "element": "baz": "value": "boo" }
     ]
   }

   The resulting JSON document:






Bryan                   Expires October 22, 2011                [Page 8]

Internet-Draft            JSON Patch Media Type               April 2011


   {
     "baz": "boo",
     "foo": "bar"
   }


Appendix B.  Changelog

   Draft 00

   o  Initial draft.


Appendix C.  Open Issues

   1.  [JSONPath] is an informal, de facto standard.  Work is now in
       progress to get it published an Internet-Draft (with some likely
       changes).

   2.  Should define an accompanying JSON-Schema specification for the
       JSON-Patch document structure.


Author's Address

   Paul C. Bryan (editor)
   ForgeRock US, Inc.
   201 NE Park Plaza Drive Suite 196
   Vancouver, WA  98684
   USA

   Phone: +1 604 783 1481
   Email: paul.bryan@forgerock.com


















Bryan                   Expires October 22, 2011                [Page 9]


Html markup produced by rfcmarkup 1.108, available from http://tools.ietf.org/tools/rfcmarkup/