draft-ietf-appsawg-json-patch-09.txt   draft-ietf-appsawg-json-patch-10.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: Standards Track M. Nottingham, Ed. Intended status: Standards Track M. Nottingham, Ed.
Expires: July 8, 2013 Akamai Expires: July 24, 2013 Akamai
January 4, 2013 January 20, 2013
JSON Patch JSON Patch
draft-ietf-appsawg-json-patch-09 draft-ietf-appsawg-json-patch-10
Abstract Abstract
JSON Patch defines the media type "application/json-patch", a JSON JSON Patch defines a JSON document structure for expressing a
document structure for expressing a sequence of operations to apply sequence of operations to apply to a JavaScript Object Notation
to a JavaScript Object Notation (JSON) document, suitable for use (JSON) document, suitable for use with the HTTP PATCH method. The
with the HTTP PATCH method. "application/json-patch" media type is used to identify such patch
documents.
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 July 8, 2013. This Internet-Draft will expire on July 24, 2013.
Copyright Notice Copyright Notice
Copyright (c) 2013 IETF Trust and the persons identified as the Copyright (c) 2013 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 12 skipping to change at page 2, line 13
the Trust Legal Provisions and are provided without warranty as the Trust Legal Provisions and are provided without warranty as
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 . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4. Operations . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4.1. add . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4.1. add . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4.2. remove . . . . . . . . . . . . . . . . . . . . . . . . . . 5 4.2. remove . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.3. replace . . . . . . . . . . . . . . . . . . . . . . . . . 6 4.3. replace . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.4. move . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 4.4. move . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.5. copy . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 4.5. copy . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.6. test . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 4.6. test . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
5. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 8 5. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 8
6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 8 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 8
7. Security Considerations . . . . . . . . . . . . . . . . . . . 9 7. Security Considerations . . . . . . . . . . . . . . . . . . . 9
8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 9 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 10
9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 10 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 10
9.1. Normative References . . . . . . . . . . . . . . . . . . . 10 9.1. Normative References . . . . . . . . . . . . . . . . . . . 10
9.2. Informative References . . . . . . . . . . . . . . . . . . 10 9.2. Informative References . . . . . . . . . . . . . . . . . . 10
Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 10 Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 11
A.1. Adding an Object Member . . . . . . . . . . . . . . . . . 10 A.1. Adding an Object Member . . . . . . . . . . . . . . . . . 11
A.2. Adding an Array Element . . . . . . . . . . . . . . . . . 11 A.2. Adding an Array Element . . . . . . . . . . . . . . . . . 11
A.3. Removing an Object Member . . . . . . . . . . . . . . . . 11 A.3. Removing an Object Member . . . . . . . . . . . . . . . . 12
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 . . . . . . . . . . . . . . . . . . . . . . 13
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 . . . . . . . . . . . . . . . 15 A.13. Invalid JSON Patch Document . . . . . . . . . . . . . . . 16
A.14. ~ Escape Ordering . . . . . . . . . . . . . . . . . . . . 16 A.14. ~ Escape Ordering . . . . . . . . . . . . . . . . . . . . 16
A.15. Comparing Strings and Numbers . . . . . . . . . . . . . . 16 A.15. Comparing Strings and Numbers . . . . . . . . . . . . . . 16
A.16. Adding an Array Value . . . . . . . . . . . . . . . . . . 17 A.16. Adding an Array Value . . . . . . . . . . . . . . . . . . 17
Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 17 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 17
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/
json-patch") for expressing a sequence of operations to apply to a json-patch") for expressing a sequence of operations to apply to a
target JSON document, suitable for use with the HTTP PATCH method. target JSON document, suitable for use with the HTTP PATCH method.
This format is also potentially useful in other cases where necessary This format is also potentially useful in other cases where necessary
to make partial updates to a JSON document. to make partial updates to a JSON document, or to a data structure
that has similar constraints (i.e., they can be serialised as an
object or an array using the JSON grammar).
2. Conventions 2. Conventions
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in RFC 2119 [RFC2119]. document are to be interpreted as described in RFC 2119 [RFC2119].
See Section 5 for information about handling errors. See Section 5 for information about handling errors.
3. Document Structure 3. Document Structure
A JSON Patch document is a JSON [RFC4627] document that represents an A JSON Patch document is a JSON [RFC4627] document that represents an
array of objects. Each object represents a single operation to be array of objects. Each object represents a single operation to be
applied to the target JSON document. applied to the target JSON document.
An example JSON Patch document: An example JSON Patch document, transferred in a HTTP PATCH request:
PATCH /my/data HTTP/1.1
Host: example.org
Content-Length: 326
Content-Type: application/json-patch
If-Match: "abc123"
[ [
{ "op": "test", "path": "/a/b/c", "value": "foo" }, { "op": "test", "path": "/a/b/c", "value": "foo" },
{ "op": "remove", "path": "/a/b/c" }, { "op": "remove", "path": "/a/b/c" },
{ "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] }, { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] },
{ "op": "replace", "path": "/a/b/c", "value": 42 }, { "op": "replace", "path": "/a/b/c", "value": 42 },
{ "op": "move", "from": "/a/b/c", "path": "/a/b/d" }, { "op": "move", "from": "/a/b/c", "path": "/a/b/d" },
{ "op": "copy", "from": "/a/b/d", "path": "/a/b/e" } { "op": "copy", "from": "/a/b/d", "path": "/a/b/e" }
] ]
Evaluation of a JSON Patch document begins against a target JSON Evaluation of a JSON Patch document begins against a target JSON
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
Operation objects MUST have exactly one "op" member, whose value Operation objects MUST have exactly one "op" member, whose value
skipping to change at page 4, line 9 skipping to change at page 4, line 15
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
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"; other values are
is defined below. errors. The semantics of each 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 That member's value is a string containing a [JSON-Pointer] value
references a location within the target document to perform the that references a location within the target document (the "target
operation (the "target location"). location") where the operation is performed.
The meanings of other members of operation objects are defined by the The meanings of other members of operation objects are defined by
operation (see the subsections below). Members that are not operation (see the subsections below). Members that are not
explicitly defined for the operation in question MUST be ignored. explicitly defined for the operation in question MUST be ignored
(i.e., the operation will complete as if the undefined member did not
appear in the object).
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 any unescaping (see [RFC4627], Section 2.5) document; i.e., after any unescaping (see [RFC4627], Section 2.5)
skipping to change at page 4, line 46 skipping to change at page 5, line 8
o If the target location specifies an array index, a new value is o If the target location specifies an array index, a new value is
inserted into the array at the specified index. inserted into the array at the specified index.
o If the target location specifies an object member that does not o If the target location specifies an object member that does not
already exist, a new member is added to the object. already exist, a new member is added to the object.
o If the target location specifies an object member that does exist, o If the target location specifies an object member that does exist,
that member's value is replaced. that member's value is replaced.
The operation object MUST contain a "value" member whose content
specifies the value to be added.
For example: For example:
{ "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] } { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] }
When the operation is applied, the target location MUST reference one When the operation is applied, the target location MUST reference one
of: of:
o The root of the target document - whereupon the specified value o The root of the target document - whereupon the specified value
becomes the entire content of the target document. becomes the entire content of the target document.
skipping to change at page 5, line 28 skipping to change at page 5, line 41
effect of appending the value to the array. effect of appending the value to the array.
Because this operation is designed to add to existing objects and Because this operation is designed to add to existing objects and
arrays, its target location will often not exist. Although the arrays, its target location will often not exist. Although the
pointer's error handling algorithm will thus be invoked, this pointer's error handling algorithm will thus be invoked, this
specification defines the error handling behaviour for "add" pointers specification defines the error handling behaviour for "add" pointers
to ignore that error and add the value as specified. to ignore that error and add the value as specified.
However, the object itself or an array containing it does need to However, the object itself or an array containing it does need to
exist, and it remains an error for that not to be the case. For exist, and it remains an error for that not to be the case. For
example, "add"ing to the path "/a/b" to this document: example, an "add" with a target location of "/a/b" starting with 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 } }
because "a" does not exist. because "a" does not exist.
skipping to change at page 6, line 9 skipping to change at page 6, line 22
{ "op": "remove", "path": "/a/b/c" } { "op": "remove", "path": "/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.
4.3. replace 4.3. replace
The "replace" operation replaces the value at the target location The "replace" operation replaces the value at the target location
with a new value. The operation object MUST contain a "value" member with a new value. The operation object MUST contain a "value" member
that specifies the replacement value. whose content specifies the replacement value.
The target location MUST exist for the operation to be successful. The target location MUST exist for the operation to be successful.
For example: For example:
{ "op": "replace", "path": "/a/b/c", "value": 42 } { "op": "replace", "path": "/a/b/c", "value": 42 }
This operation is functionally identical to a "remove" operation for This operation is functionally identical to a "remove" operation for
a value, followed immediately by an "add" operation at the same a value, followed immediately by an "add" operation at the same
location with the replacement value. location with the replacement value.
skipping to change at page 7, line 10 skipping to change at page 7, line 24
containing a JSON Pointer value that references the location in the containing a JSON Pointer value that references the location in the
target document to copy the value from. target document to copy the value from.
The "from" location MUST exist for the operation to be successful. The "from" location MUST exist for the operation to be successful.
For example: For example:
{ "op": "copy", "from": "/a/b/c", "path": "/a/b/e" } { "op": "copy", "from": "/a/b/c", "path": "/a/b/e" }
This operation is functionally identical to an "add" operation at the This operation is functionally identical to an "add" operation at the
target location using the value specified in the "from". target location using the value specified in the "from" member.
4.6. test 4.6. test
The "test" operation tests that a value at the target location is The "test" operation tests that a value at the target location is
equal to a specified value. equal to a specified value.
The operation object MUST contain a "value" member that conveys the The operation object MUST contain a "value" member that conveys the
value to be compared to that at the target location. value to be compared to that at the target location.
The target location MUST be equal to the "value" value for the The target location MUST be equal to the "value" value for the
skipping to change at page 16, line 4 skipping to change at page 16, line 14
A.13. Invalid JSON Patch Document A.13. Invalid JSON Patch Document
A JSON Patch document: A JSON Patch document:
[ [
{ "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. JSON requires that
hides such duplicate element names therefore cannot be used unless it object member names be unique with a "SHOULD" requirement, and there
always exposes only the last element with a given name (eg is no standard error handling for duplicates.
"op":"remove" in this example).
A.14. ~ Escape Ordering A.14. ~ Escape Ordering
An example target JSON document: An example target JSON document:
{ {
"/": 9, "/": 9,
"~1": 10 "~1": 10
} }
 End of changes. 23 change blocks. 
34 lines changed or deleted 47 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/