draft-ietf-appsawg-json-patch-07.txt   draft-ietf-appsawg-json-patch-08.txt 
Applications Area Working Group P. Bryan, Ed. Applications Area Working Group P. Bryan, Ed.
Internet-Draft Salesforce.com Internet-Draft Salesforce.com
Intended status: Informational M. Nottingham, Ed. Intended status: Informational M. Nottingham, Ed.
Expires: June 8, 2013 Akamai Expires: June 14, 2013 Akamai
December 5, 2012 December 11, 2012
JSON Patch JSON Patch
draft-ietf-appsawg-json-patch-07 draft-ietf-appsawg-json-patch-08
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, suitable for use with the HTTP PATCH method.
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
provisions of BCP 78 and BCP 79. provisions of BCP 78 and BCP 79.
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 June 8, 2013. This Internet-Draft will expire on June 14, 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 38 skipping to change at page 2, line 38
A.4. Removing an Array Element . . . . . . . . . . . . . . . . 12 A.4. Removing an Array Element . . . . . . . . . . . . . . . . 12
A.5. Replacing a Value . . . . . . . . . . . . . . . . . . . . 12 A.5. Replacing a Value . . . . . . . . . . . . . . . . . . . . 12
A.6. Moving a Value . . . . . . . . . . . . . . . . . . . . . . 12 A.6. Moving a Value . . . . . . . . . . . . . . . . . . . . . . 12
A.7. Moving an Array Element . . . . . . . . . . . . . . . . . 13 A.7. Moving an Array Element . . . . . . . . . . . . . . . . . 13
A.8. Testing a Value: Success . . . . . . . . . . . . . . . . . 14 A.8. Testing a Value: Success . . . . . . . . . . . . . . . . . 14
A.9. Testing a Value: Error . . . . . . . . . . . . . . . . . . 14 A.9. Testing a Value: Error . . . . . . . . . . . . . . . . . . 14
A.10. Adding a nested Member Object . . . . . . . . . . . . . . 14 A.10. Adding a nested Member Object . . . . . . . . . . . . . . 14
A.11. Ignoring Unrecognized Elements . . . . . . . . . . . . . . 15 A.11. Ignoring Unrecognized Elements . . . . . . . . . . . . . . 15
A.12. Adding to a Non-existant Target . . . . . . . . . . . . . 15 A.12. Adding to a Non-existant Target . . . . . . . . . . . . . 15
A.13. Invalid JSON Patch Document . . . . . . . . . . . . . . . 16 A.13. Invalid JSON Patch Document . . . . . . . . . . . . . . . 16
A.14. ~ Escape Ordering . . . . . . . . . . . . . . . . . . . . 16
Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 16 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 16
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.
JSON Patch is a format (identified by the media type "application/ JSON Patch is a format (identified by the media type "application/
skipping to change at page 4, line 17 skipping to change at page 4, line 17
Operation objects MUST have exactly one "op" member, whose value Operation objects MUST have exactly one "op" member, whose value
indicates the operation to perform. Its value MUST be one of "add", indicates the operation to perform. Its value MUST be one of "add",
"remove", "replace", "move", "copy" or "test". The semantics of each "remove", "replace", "move", "copy" or "test". The semantics of each
is defined below. is defined below.
Additionally, operation objects MUST have exactly one "path" member, Additionally, operation objects MUST have exactly one "path" member,
whose value MUST be a string containing a [JSON-Pointer] value that whose value MUST be a string containing a [JSON-Pointer] value that
references a location within the target document to perform the references a location within the target document to perform the
operation (the "target location"). operation (the "target location").
Other members of operation objects MUST be ignored, unless they are The meanings of other members of operation objects are defined by the
explicitly allowed by the definition of the operation. operation (see the subsections below). Members that are not
explicitly defined for the operation in question MUST be ignored.
Note that the ordering of members in JSON objects is not significant; Note that the ordering of members in JSON objects is not significant;
therefore, the following operation objects are equivalent: therefore, the following operation objects are equivalent:
{ "op": "add", "path": "/a/b/c", "value": "foo" } { "op": "add", "path": "/a/b/c", "value": "foo" }
{ "path": "/a/b/c", "op": "add", "value": "foo" } { "path": "/a/b/c", "op": "add", "value": "foo" }
{ "value": "foo", "path": "/a/b/c", "op": "add" } { "value": "foo", "path": "/a/b/c", "op": "add" }
Operations are applied to the data structures represented by a JSON Operations are applied to the data structures represented by a JSON
document; i.e., after unescaping takes place. document; i.e., after unescaping takes place.
skipping to change at page 5, line 9 skipping to change at page 5, line 10
member already exists, it is replaced by the specified value. member already exists, it is replaced by the specified value.
o An element to add to an existing array - whereupon the supplied o An element to add to an existing array - whereupon the supplied
value is added to the array at the indicated location. Any value is added to the array at the indicated location. Any
elements at or above the specified index are shifted one position elements at or above the specified index are shifted one position
to the right. The specified index MUST NOT be greater than the to the right. The specified index MUST NOT be greater than the
number of elements in the array. If the "-" character is used to number of elements in the array. If the "-" character is used to
index the end of the array, this has the effect of appending the index the end of the array, this has the effect of appending the
value to the array. value to the array.
Note that this operation can, in common use, have a target location Because this operation is designed to add to existing objects and
that does not resolve to an existing value, resulting in the arrays, its target location will often not resolve to an existing
pointer's error handling algorithm being invoked. This specification value. Although the pointer's error handling algorithm will thus be
defines the error handling algorithm for "add" pointers to explicitly invoked, this specification defines the error handling behaviour for
ignore the error and perform the operation as specified. "add" pointers to ignore that error and add value as specified.
However, if the object or array containing it does not exist, it is The object itself or an array containing it, however, has to exist,
an error. and it remains an error for that not to be the case.
For example, "add"ing to the path "/a/b" to this document: For example, "add"ing to the path "/a/b" to this document:
{ "a": { "foo": 1 } } { "a": { "foo": 1 } }
is not an error, because "a" exists, and "b" will be added to its is not an error, because "a" exists, and "b" will be added to its
value. It is an error in this document: value. It is an error in this document:
{ "q": { "bar": 2 } } { "q": { "bar": 2 } }
skipping to change at page 7, line 50 skipping to change at page 7, line 50
Also, note that ordering of the serialisation of object members is Also, note that ordering of the serialisation of object members is
not significant. not significant.
For example: For example:
{ "op": "test", "path": "/a/b/c", "value": "foo" } { "op": "test", "path": "/a/b/c", "value": "foo" }
5. Error Handling 5. Error Handling
If a RFC2119 [RFC2119] requirement is violated by a JSON Patch If a normative requirement is violated by a JSON Patch document, or
document, or if an operation is not successful, evaluation of the if an operation is not successful, evaluation of the JSON Patch
JSON Patch document SHOULD terminate and application of the entire document SHOULD terminate and application of the entire patch
patch document SHALL NOT be deemed successful. document SHALL NOT be deemed successful.
See [RFC5789], Section 2.2 for considerations regarding handling See [RFC5789], Section 2.2 for considerations regarding handling
errors when JSON Patch is used with the HTTP PATCH method, including errors when JSON Patch is used with the HTTP PATCH method, including
suggested status codes to use to indicate various conditions. suggested status codes to use to indicate various conditions.
Note that the HTTP PATCH method is atomic, as per [RFC5789]. Note that the HTTP PATCH method is atomic, as per [RFC5789].
Therefore, the following patch would result in no changes being made Therefore, the following patch would result in no changes being made
to the document at all (because the "test" operation results in an to the document at all (because the "test" operation results in an
error). error).
skipping to change at page 10, line 11 skipping to change at page 10, line 11
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., Zyp, K., and M. Nottingham, "JSON Pointer", Bryan, P., Zyp, K., and M. Nottingham, "JSON Pointer",
draft-ietf-appsawg-json-pointer-06 (work in progress), draft-ietf-appsawg-json-pointer-07 (work in progress),
November 2012. November 2012.
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", BCP 14, RFC 2119, March 1997. Requirement Levels", BCP 14, RFC 2119, March 1997.
[RFC4627] Crockford, D., "The application/json Media Type for [RFC4627] Crockford, D., "The application/json Media Type for
JavaScript Object Notation (JSON)", RFC 4627, July 2006. JavaScript Object Notation (JSON)", RFC 4627, July 2006.
9.2. Informative References 9.2. Informative References
skipping to change at page 16, line 19 skipping to change at page 16, line 19
[ [
{ "op": "add", "path": "/baz", "value": "qux", "op": "remove" } { "op": "add", "path": "/baz", "value": "qux", "op": "remove" }
] ]
This JSON Patch document cannot be treated as an "add" operation This JSON Patch document cannot be treated as an "add" operation
since there is a later "op":"remove" element. A JSON parser that since there is a later "op":"remove" element. A JSON parser that
hides such duplicate element names therefore cannot be used unless it hides such duplicate element names therefore cannot be used unless it
always exposes only the last element with a given name (eg always exposes only the last element with a given name (eg
"op":"remove" in this example). "op":"remove" in this example).
A.14. ~ Escape Ordering
A JSON Patch document:
{
"/": 9,
"~1": 10
}
A JSON Patch document:
[
{"op": "test", "path": "/~01", "value":"10"}
]
The resulting JSON document:
{
"/": 9,
"~1": 10
}
Authors' Addresses Authors' Addresses
Paul C. Bryan (editor) Paul C. Bryan (editor)
Salesforce.com Salesforce.com
Phone: +1 604 783 1481 Phone: +1 604 783 1481
Email: pbryan@anode.ca Email: pbryan@anode.ca
Mark Nottingham (editor) Mark Nottingham (editor)
Akamai Akamai
Email: mnot@mnot.net Email: mnot@mnot.net
 End of changes. 12 change blocks. 
20 lines changed or deleted 43 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/