draft-ietf-appsawg-json-patch-01.txt   draft-ietf-appsawg-json-patch-02.txt 
Applications Area Working Group P. Bryan, Ed. Applications Area Working Group P. Bryan, Ed.
Internet-Draft ForgeRock Internet-Draft ForgeRock
Intended status: Informational March 9, 2012 Intended status: Informational M. Nottingham, Ed.
Expires: September 10, 2012 Expires: January 5, 2013 Rackspace
July 4, 2012
JSON Patch JSON Patch
draft-ietf-appsawg-json-patch-01 draft-ietf-appsawg-json-patch-02
Abstract Abstract
JSON Patch defines the media type "application/json-patch", a JSON JSON Patch defines the media type "application/json-patch", a JSON
document structure for expressing a sequence of operations to apply document structure for expressing a sequence of operations to apply
to a JSON document. to a JSON document.
Status of this Memo Status of this Memo
This Internet-Draft is submitted in full conformance with the This Internet-Draft is submitted in full conformance with the
skipping to change at page 1, line 32 skipping to change at page 1, line 33
Internet-Drafts are working documents of the Internet Engineering Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF). Note that other groups may also distribute Task Force (IETF). Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet- working documents as Internet-Drafts. The list of current Internet-
Drafts is at http://datatracker.ietf.org/drafts/current/. Drafts is at http://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months Internet-Drafts are draft documents valid for a maximum of six months
and may be updated, replaced, or obsoleted by other documents at any and may be updated, replaced, or obsoleted by other documents at any
time. It is inappropriate to use Internet-Drafts as reference time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress." material or to cite them other than as "work in progress."
This Internet-Draft will expire on September 10, 2012. This Internet-Draft will expire on January 5, 2013.
Copyright Notice Copyright Notice
Copyright (c) 2012 IETF Trust and the persons identified as the Copyright (c) 2012 IETF Trust and the persons identified as the
document authors. All rights reserved. document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents Provisions Relating to IETF Documents
(http://trustee.ietf.org/license-info) in effect on the date of (http://trustee.ietf.org/license-info) in effect on the date of
publication of this document. Please review these documents publication of this document. Please review these documents
skipping to change at page 2, line 13 skipping to change at page 2, line 13
described in the Simplified BSD License. described in the Simplified BSD License.
Table of Contents Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3
2. Conventions . . . . . . . . . . . . . . . . . . . . . . . . . 3 2. Conventions . . . . . . . . . . . . . . . . . . . . . . . . . 3
3. Document Structure . . . . . . . . . . . . . . . . . . . . . . 3 3. Document Structure . . . . . . . . . . . . . . . . . . . . . . 3
4. Operations . . . . . . . . . . . . . . . . . . . . . . . . . . 3 4. Operations . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4.1. add . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4.1. add . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4.2. remove . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4.2. remove . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4.3. replace . . . . . . . . . . . . . . . . . . . . . . . . . 4 4.3. replace . . . . . . . . . . . . . . . . . . . . . . . . . 5
4.4. move . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 4.4. move . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4.5. copy . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 4.5. copy . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.6. test . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 4.6. test . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
5. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 6 5. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 6
6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 6 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 7
7. Security Considerations . . . . . . . . . . . . . . . . . . . 7 7. Security Considerations . . . . . . . . . . . . . . . . . . . 8
8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 7 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 8
9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 8 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 8
9.1. Normative References . . . . . . . . . . . . . . . . . . . 8 9.1. Normative References . . . . . . . . . . . . . . . . . . . 8
9.2. Informative References . . . . . . . . . . . . . . . . . . 8 9.2. Informative References . . . . . . . . . . . . . . . . . . 8
Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 8 Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 9
A.1. Adding an Object Member . . . . . . . . . . . . . . . . . 8 A.1. Adding an Object Member . . . . . . . . . . . . . . . . . 9
A.2. Adding an Array Element . . . . . . . . . . . . . . . . . 9 A.2. Adding an Array Element . . . . . . . . . . . . . . . . . 9
A.3. Removing an Object Member . . . . . . . . . . . . . . . . 9 A.3. Removing an Object Member . . . . . . . . . . . . . . . . 9
A.4. Removing an Array Element . . . . . . . . . . . . . . . . 10 A.4. Removing an Array Element . . . . . . . . . . . . . . . . 10
A.5. Replacing a Value . . . . . . . . . . . . . . . . . . . . 10 A.5. Replacing a Value . . . . . . . . . . . . . . . . . . . . 10
A.6. Moving a Value . . . . . . . . . . . . . . . . . . . . . . 11 A.6. Moving a Value . . . . . . . . . . . . . . . . . . . . . . 11
A.7. Moving an Array Element . . . . . . . . . . . . . . . . . 11 A.7. Moving an Array Element . . . . . . . . . . . . . . . . . 11
A.8. Testing a Value: Success . . . . . . . . . . . . . . . . . 12 A.8. Testing a Value: Success . . . . . . . . . . . . . . . . . 12
A.9. Testing a Value: Error . . . . . . . . . . . . . . . . . . 12 A.9. Testing a Value: Error . . . . . . . . . . . . . . . . . . 12
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 12 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 13
1. Introduction 1. Introduction
JavaScript Object Notation (JSON) [RFC4627] is a common format for JavaScript Object Notation (JSON) [RFC4627] is a common format for
the exchange and storage of structured data. HTTP PATCH [RFC5789] the exchange and storage of structured data. HTTP PATCH [RFC5789]
extends the Hypertext Transfer Protocol (HTTP) [RFC2616] with a extends the Hypertext Transfer Protocol (HTTP) [RFC2616] with a
method to perform partial modifications to resources. method to perform partial modifications to resources.
The JSON Patch media type "application/json-patch" is a JSON document The JSON Patch media type "application/json-patch" is a JSON document
structure for expressing a sequence of operations to apply to a structure for expressing a sequence of operations to apply to a
skipping to change at page 3, line 49 skipping to change at page 3, line 49
document. Operations are applied sequentially in the order they document. Operations are applied sequentially in the order they
appear in the array. Each operation in the sequence is applied to appear in the array. Each operation in the sequence is applied to
the target document; the resulting document becomes the target of the the target document; the resulting document becomes the target of the
next operation. Evaluation continues until all operations are next operation. Evaluation continues until all operations are
successfully applied or an error condition is encountered. successfully applied or an error condition is encountered.
4. Operations 4. Operations
The operation to perform is expressed in a member of the operation The operation to perform is expressed in a member of the operation
object. The name of the operation member is one of: "add", "remove", object. The name of the operation member is one of: "add", "remove",
"replace", "move", "copy" or "test". The member value is a string "replace", "move", "copy" or "test".
containing a [JSON-Pointer] value, which references the location
within the target document to perform the operation. It is an error The member value is a string containing a [JSON-Pointer] value that
condition if an operation object contains no recognized operation references the location within the target document to perform the
member or more than one operation member. operation. It is an error condition if an operation object contains
no recognized operation member or more than one operation member.
4.1. add 4.1. add
The "add" operation adds a new value at the specified location in the The "add" operation adds a new value at the specified location in the
target document. The location must reference one of: the root of the target document. The location must reference one of: the root of the
target document, a member to add to an existing object, or an element target document, a member to add to an existing object, or an element
to add to an existing array. The operation object contains a "value" to add to an existing array. The operation object contains a "value"
member, which specifies the value to be added. member that specifies the value to be added.
Example: Example:
{ "add": "/a/b/c", "value": [ "foo", "bar" ] } { "add": "/a/b/c", "value": [ "foo", "bar" ] }
If the location references the root of the target document or a If the location references the root of the target document or a
member of an existing object, it is an error condition if a value at member of an existing object, it is an error condition if a value at
the specified location already exists. the specified location already exists.
If the location references an element of an existing array, any If the location references an element of an existing array, any
elements at or above the specified index are shifted one position to elements at or above the specified index are shifted one position to
the right. It is an error condition if the specified index is the right. It is an error condition if the specified index is
greater than the number of elements in the array. greater than the number of elements in the array.
Note that this operation will, in common use, contain a JSON Pointer
that does not resolve to an existing value in the target document.
As such, the pointer's error handling algorithm is invoked. This
specification defines the error handling algorithm for "add" pointers
to explicitly ignore the error and perform the operation as
specified.
4.2. remove 4.2. remove
The "remove" operation removes the value at the specified location in The "remove" operation removes the value at the specified location in
the target document. the target document.
Example: Example:
{ "remove": "/a/b/c" } { "remove": "/a/b/c" }
If removing an element from an array, any elements above the If removing an element from an array, any elements above the
specified index are shifted one position to the left. specified index are shifted one position to the left.
It is an error condition if a value at the specified location does It is an error condition if a value at the specified location does
not exist. not exist.
4.3. replace 4.3. replace
The "replace" operation replaces the value at the specified location The "replace" operation replaces the value at the specified location
in the target document with a new value. The operation object in the target document with a new value. The operation object
contains a "value" member, which specifies the replacement value. contains a "value" member that specifies the replacement value.
Example: Example:
{ "replace": "/a/b/c", "value": 42 } { "replace": "/a/b/c", "value": 42 }
This operation is functionally identical to expressing a "remove" This operation is functionally identical to expressing a "remove"
operation for a value, followed immediately by an "add" operation at operation for a value, followed immediately by an "add" operation at
the same location with the replacement value. the same location with the replacement value.
It is an error condition if a value at the specified location does It is an error condition if a value at the specified location does
not exist. not exist.
4.4. move 4.4. move
The "move" operation removes the value at one location and adds it to The "move" operation removes the value at one location and adds it to
another location in the target document. another location in the target document.
The operation object contains a "to" member, a string containing a The operation object contains a "to" member, a string containing a
JSON Pointer value, which references the location in the target JSON Pointer value that references the location in the target
document to add the value to. This location must reference one of: document to add the value to. This location must reference one of:
the member to add to an existing object, or an element to add to an the member to add to an existing object, or an element to add to an
existing array. existing array.
Example: Example:
{ "move": "/a/b/c", "to": "/a/b/d" } { "move": "/a/b/c", "to": "/a/b/d" }
This operation is functionally identical to expressing a "remove" This operation is functionally identical to expressing a "remove"
operation, followed immediately by an "add" operation at the new operation, followed immediately by an "add" operation at the new
location with the value that was just removed. Moving a value to its location with the value that was just removed. Moving a value to its
current location can be safely ignored. current location can be safely ignored.
If the location in the "to" member references a member of an existing If the location in the "to" member references a member of an existing
object in the target document, it is an error condition if a value at object in the target document, it is an error condition if a value at
the specified location already exists. the specified location already exists (unless "move" and "to" specify
the same object, which has no effect).
If the location in the "to" member references an element of an If the location in the "to" member references an element of an
existing array, any elements at or above the specified index are existing array, any elements at or above the specified index are
shifted one position to the right. It is an error condition if the shifted one position to the right. It is an error condition if the
specified index is greater than the number of elements in the array. specified index is greater than the number of elements in the array.
4.5. copy 4.5. copy
The "copy" operation copies the value at one location to another The "copy" operation copies the value at one location to another
location in the target document. location in the target document.
The operation object contains a "to" member, a string containing a The operation object contains a "to" member, a string containing a
JSON Pointer value, which references the location in the target JSON Pointer value that references the location in the target
document to add the value to. This location must reference one of: document to add the value to. This location must reference one of:
the member to add to an existing object, or an element to add to an the member to add to an existing object, or an element to add to an
existing array. existing array.
Example: Example:
{ "copy": "/a/b/c", "to": "/a/b/e" } { "copy": "/a/b/c", "to": "/a/b/e" }
If the location in the "to" member references a member of an existing If the location in the "to" member references a member of an existing
object in the target document, it is an error condition if a value at object in the target document, it is an error condition if a value at
the specified location already exists. the specified location already exists.
skipping to change at page 6, line 25 skipping to change at page 6, line 33
If the location in the "to" member references an element of an If the location in the "to" member references an element of an
existing array, any elements at or above the specified index are existing array, any elements at or above the specified index are
shifted one position to the right. It is an error condition if the shifted one position to the right. It is an error condition if the
specified index is greater than the number of elements in the array. specified index is greater than the number of elements in the array.
4.6. test 4.6. test
The "test" operation tests that a value at the specified location in The "test" operation tests that a value at the specified location in
the target document is equal to a specified value. The operation the target document is equal to a specified value. The operation
object contains a "value" member, which specifies the value to test object contains a "value" member that specifies the value to test
for. If values are or contain objects or arrays, they must be for. If values are or contain objects or arrays, they must be
identical (i.e. same order of elements, with the same values). identical (i.e. same order of elements, with the same values).
Example: Example:
{ "test": "/a/b/c", "value": "foo" } { "test": "/a/b/c", "value": "foo" }
It is an error condition if the value at the specified location is It is an error condition if the value at the specified location is
not equal to the specified value. not equal to the specified value.
skipping to change at page 7, line 49 skipping to change at page 8, line 12
Change controller: IETF Change controller: IETF
7. Security Considerations 7. Security Considerations
This specification has the same security considerations as JSON This specification has the same security considerations as JSON
[RFC4627] and [JSON-Pointer]. [RFC4627] and [JSON-Pointer].
8. Acknowledgements 8. Acknowledgements
The following individuals contributed ideas, feedback and wording, The following individuals contributed ideas, feedback and wording to
which contributed to the content of this specification: this specification:
Mike Acar, Mike Amundsen, Paul Davis, Murray S. Kucherawy, Dean Mike Acar, Mike Amundsen, Paul Davis, Murray S. Kucherawy, Dean
Landolt, Randall Leeds, Mark Nottingham, Julian Reschke, Eli Landolt, Randall Leeds, Julian Reschke, Eli Stevens.
Stevens.
The structure of a JSON Patch document was influenced by the XML The structure of a JSON Patch document was influenced by the XML
Patch document [RFC5261] specification. Patch document [RFC5261] specification.
9. References 9. References
9.1. Normative References 9.1. Normative References
[JSON-Pointer] [JSON-Pointer]
Bryan, P. and K. Zyp, "JSON Pointer", Bryan, P. and K. Zyp, "JSON Pointer",
skipping to change at page 12, line 18 skipping to change at page 12, line 30
A.8. Testing a Value: Success A.8. Testing a Value: Success
An example target JSON document: An example target JSON document:
{ {
"baz": "qux", "baz": "qux",
"foo": [ "a", 2, "c" ] "foo": [ "a", 2, "c" ]
} }
A JSON Patch document, which will result in successful evaluation: A JSON Patch document that will result in successful evaluation:
[ [
{ "test": "/baz", "value": "qux" }, { "test": "/baz", "value": "qux" },
{ "test": "/foo/1", "value": 2 } { "test": "/foo/1", "value": 2 }
] ]
A.9. Testing a Value: Error A.9. Testing a Value: Error
An example target JSON document: An example target JSON document:
{ {
"baz": "qux" "baz": "qux"
} }
A JSON Patch document, which will result in an error condition: A JSON Patch document that will result in an error condition:
[ [
{ "test": "/baz", "value": "bar" } { "test": "/baz", "value": "bar" }
] ]
Author's Address Authors' Addresses
Paul C. Bryan (editor) Paul C. Bryan (editor)
ForgeRock ForgeRock
Phone: +1 604 783 1481 Phone: +1 604 783 1481
Email: pbryan@anode.ca Email: pbryan@anode.ca
Mark Nottingham (editor)
Rackspace
Email: mnot@mnot.net
 End of changes. 23 change blocks. 
31 lines changed or deleted 39 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/