| < draft-ietf-appsawg-json-patch-05.txt | draft-ietf-appsawg-json-patch-06.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: March 30, 2013 September 26, 2012 | Expires: April 25, 2013 October 22, 2012 | |||
| JSON Patch | JSON Patch | |||
| draft-ietf-appsawg-json-patch-05 | draft-ietf-appsawg-json-patch-06 | |||
| 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 32 ¶ | |||
| 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 March 30, 2013. | This Internet-Draft will expire on April 25, 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 21 ¶ | skipping to change at page 2, line 21 ¶ | |||
| 4.1. add . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 | 4.1. add . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 | |||
| 4.2. remove . . . . . . . . . . . . . . . . . . . . . . . . . . 5 | 4.2. remove . . . . . . . . . . . . . . . . . . . . . . . . . . 5 | |||
| 4.3. replace . . . . . . . . . . . . . . . . . . . . . . . . . 5 | 4.3. replace . . . . . . . . . . . . . . . . . . . . . . . . . 5 | |||
| 4.4. move . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 | 4.4. move . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 | |||
| 4.5. copy . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 | 4.5. copy . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 | |||
| 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 . . . . . . . . . . . . . . . . . . . . . . . 9 | |||
| 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 9 | 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 10 | |||
| 9.1. Normative References . . . . . . . . . . . . . . . . . . . 9 | 9.1. Normative References . . . . . . . . . . . . . . . . . . . 10 | |||
| 9.2. Informative References . . . . . . . . . . . . . . . . . . 10 | 9.2. Informative References . . . . . . . . . . . . . . . . . . 10 | |||
| Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 10 | Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 10 | |||
| A.1. Adding an Object Member . . . . . . . . . . . . . . . . . 10 | A.1. Adding an Object Member . . . . . . . . . . . . . . . . . 10 | |||
| 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 . . . . . . . . . . . . . . . . 11 | |||
| A.4. Removing an Array Element . . . . . . . . . . . . . . . . 11 | A.4. Removing an Array Element . . . . . . . . . . . . . . . . 11 | |||
| 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 . . . . . . . . . . . . . . . . . 13 | 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 | |||
| Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 14 | A.11. Ignoring Unrecognized Elements . . . . . . . . . . . . . . 15 | |||
| A.12. Adding to a Non-existant Target . . . . . . . . . . . . . 15 | ||||
| A.13. Invalid JSON Patch Document . . . . . . . . . . . . . . . 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/ | |||
| json-patch") for expressing a sequence of operations to apply to a | json-patch") for expressing a sequence of operations to apply to a | |||
| skipping to change at page 3, line 26 ¶ | skipping to change at page 3, line 26 ¶ | |||
| 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 whose root object | A JSON Patch document is a JSON [RFC4627] document whose root is an | |||
| is an array of objects. Each object represents a single operation to | array of objects. Each object represents a single operation to be | |||
| be applied to the target JSON document. | applied to the target JSON document. | |||
| An example JSON Patch document: | An example JSON Patch document: | |||
| [ | [ | |||
| { "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", "path": "/a/b/c", "to": "/a/b/d" }, | { "op": "move", "path": "/a/b/c", "to": "/a/b/d" }, | |||
| { "op": "copy", "path": "/a/b/c", "to": "/a/b/e" } | { "op": "copy", "path": "/a/b/d", "to": "/a/b/e" } | |||
| ] | ] | |||
| Evaluation of a JSON Patch document begins with a target JSON | Evaluation of a JSON Patch document begins with 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 | |||
| skipping to change at page 4, line 46 ¶ | skipping to change at page 4, line 46 ¶ | |||
| o the root of the target document, | o the root of the target document, | |||
| o a member to add to an existing object, or | o a member to add to an existing object, or | |||
| o an element to add to an existing array. | o an element to add to an existing array. | |||
| For example: | For example: | |||
| { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] } | { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] } | |||
| If the target location references the root of the target document or | ||||
| a member of an existing object, the specified location MUST already | ||||
| exist for the operation to be successful. | ||||
| If the target location references an element of an existing array, | If the target location references an element of an existing array, | |||
| any elements at or above the specified index are shifted one position | any 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. | number of elements in the array. | |||
| When the "-" character is used to index the end of the array, this | ||||
| has the effect of appending the value to the array. | ||||
| Note that this operation will, in common use, have a target location | Note that this operation will, in common use, have a target location | |||
| that does not resolve to an existing value, resulting in the | that does not resolve to an existing value, resulting in the | |||
| pointer's error handling algorithm being invoked. This specification | pointer's error handling algorithm being invoked. This specification | |||
| defines the error handling algorithm for "add" pointers to explicitly | defines the error handling algorithm for "add" pointers to explicitly | |||
| ignore the error and perform the operation as specified. | 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. | The "remove" operation removes the value at the target location. | |||
| The value at the specified location MUST exist for the operation to | The target location MUST exist for the operation to be successful. | |||
| be successful. | ||||
| For example: | For example: | |||
| { "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 specified 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. | that specifies the replacement value. | |||
| The value at the specified location MUST exist for the operation to | The target location MUST exist for the operation to be successful. | |||
| 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 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. | |||
| 4.4. move | 4.4. move | |||
| The "move" operation removes the value at the specified location and | The "move" operation removes the value at the target location and | |||
| adds it to another location in the target document. | adds it to another location. | |||
| The operation object MUST contain a "to" member, a string containing | The operation object MUST contain a "to" member, a string containing | |||
| a JSON Pointer value that references the location in the target | a JSON Pointer value that references the location in the target | |||
| document to add the value to. | document to add the value to. | |||
| The "to" location MUST reference one of: | The "to" location MUST reference one of: | |||
| o the member to add to an existing object, or | o the member to add to an existing object, or | |||
| o an element to add to an existing array. | o an element to add to an existing array. | |||
| For example: | For example: | |||
| { "op": "move", "path": "/a/b/c", "to": "/a/b/d" } | { "op": "move", "path": "/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 on the specified location, followed immediately by an "add" | operation on the target location, followed immediately by an "add" | |||
| operation at the "to" location with the value that was just removed. | operation at the "to" location with the value that was just removed. | |||
| The location in the "to" member MUST NOT be part of the location | ||||
| defined by "path"; i.e., a location cannot be moved into one of its | ||||
| children. | ||||
| The location in the "to" member MUST NOT reference a member of an | The location in the "to" member MUST NOT reference a member of an | |||
| existing object in the target document, unless "move" and "to" | existing object in the target document, unless "path" and "to" | |||
| specify the same object, which has no effect. | 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. The specified index MUST NOT be | shifted one position to the right. The specified index MUST NOT be | |||
| greater than the number of elements in the array. | greater than the number of elements in the array. | |||
| 4.5. copy | 4.5. copy | |||
| The "copy" operation copies the value at the specified location to | The "copy" operation copies the value at the target location to | |||
| another location in the target document. | another location. | |||
| The operation object MUST contain a "to" member, a string containing | The operation object MUST contain a "to" member, a string containing | |||
| a JSON Pointer value that references the location in the target | a JSON Pointer value that references the location in the target | |||
| document to add the value to. | document to add the value to. | |||
| This location MUST reference one of: | This location MUST reference one of: | |||
| o the member to add to an existing object, or | o the member to add to an existing object, or | |||
| o an element to add to an existing array. | o an element to add to an existing array. | |||
| For example: | For example: | |||
| { "op": "copy", "path": "/a/b/c", "to": "/a/b/e" } | { "op": "copy", "path": "/a/b/c", "to": "/a/b/e" } | |||
| The location in the "to" member MUST NOT be part of the location | ||||
| defined by "path"; i.e., a location cannot be copied into one of its | ||||
| children. | ||||
| The location in the "to" member MUST NOT reference a member of an | The location in the "to" member MUST NOT reference a member of an | |||
| existing object in the target document, unless "move" and "to" | existing object in the target document, unless "path" and "to" | |||
| specify the same object, which has no effect. | 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. The specified index MUST NOT be | shifted one position to the right. The specified index MUST NOT be | |||
| greater than the number of elements in the array. | 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 is | The "test" operation tests that a value at the target location is | |||
| equal to a 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 specified location. | value to be compared to that at the target location. | |||
| The value at the specified location MUST be equal to the specified | The target location MUST be equal to the "value" value for the | |||
| value for the operation to be considered successful. | operation to be considered successful. | |||
| Here, "equal" means that the value at the specified location and the | Here, "equal" means that the value at the target location and the | |||
| value conveyed by "value" are of the same JSON type, and considered | value conveyed by "value" are of the same JSON type, and considered | |||
| equal by the following rules for that type: | equal by the following rules for that type: | |||
| o strings: are considered equal if, after unescaping any sequence(s) | o strings: are considered equal if, after unescaping any sequence(s) | |||
| in both strings starting with a reverse solidus, they contain the | in both strings starting with a reverse solidus, they contain the | |||
| same number of Unicode characters and their code points are | same number of Unicode characters and their code points are | |||
| position-wise equal. | position-wise equal. | |||
| o numbers: are considered equal if subtracting one from the other | o numbers: are considered equal if subtracting one from the other | |||
| results in 0. | results in 0. | |||
| skipping to change at page 8, line 22 ¶ | skipping to change at page 8, line 26 ¶ | |||
| 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 as per [RFC5789], when used with the PATCH HTTP method, it | Note that as per [RFC5789], when used with the PATCH HTTP method, it | |||
| is atomic. Therefore, the following patch would result in no changes | is atomic. Therefore, the following patch would result in no changes | |||
| being made to the document at all (because the "test" operation | being made to the document at all (because the "test" operation | |||
| results in an error). | results in an error). | |||
| [ | [ | |||
| { "op": "replace", "path": "/a/b/c", "value": 42 }, | { "op": "replace", "path": "/a/b/c", "value": 42 }, | |||
| { "op": "test", "path": "/a/b/c", "value": "C" } | { "op": "test", "path": "/a/b/c", "value": "C" } | |||
| ] | ] | |||
| 6. IANA Considerations | 6. IANA Considerations | |||
| The Internet media type for a JSON Patch document is application/ | The Internet media type for a JSON Patch document is application/ | |||
| json-patch. | json-patch. | |||
| Type name: application | Type name: application | |||
| Subtype name: json-patch | Subtype name: json-patch | |||
| skipping to change at page 10, line 33 ¶ | skipping to change at page 10, line 37 ¶ | |||
| [RFC5789] Dusseault, L. and J. Snell, "PATCH Method for HTTP", | [RFC5789] Dusseault, L. and J. Snell, "PATCH Method for HTTP", | |||
| RFC 5789, March 2010. | RFC 5789, March 2010. | |||
| Appendix A. Examples | Appendix A. Examples | |||
| A.1. Adding an Object Member | A.1. Adding an Object Member | |||
| An example target JSON document: | An example target JSON document: | |||
| { | { | |||
| "foo": "bar" | "foo": "bar" | |||
| } | } | |||
| A JSON Patch document: | A JSON Patch document: | |||
| [ | [ | |||
| { "op": "add", "path": "/baz", "value": "qux" } | { "op": "add", "path": "/baz", "value": "qux" } | |||
| ] | ] | |||
| The resulting JSON document: | The resulting JSON document: | |||
| { | { | |||
| "baz": "qux", | "baz": "qux", | |||
| "foo": "bar" | "foo": "bar" | |||
| } | } | |||
| A.2. Adding an Array Element | A.2. Adding an Array Element | |||
| An example target JSON document: | An example target JSON document: | |||
| { | { | |||
| "foo": [ "bar", "baz" ] | "foo": [ "bar", "baz" ] | |||
| } | } | |||
| A JSON Patch document: | A JSON Patch document: | |||
| [ | [ | |||
| { "op": "add", "path": "/foo/1", "value": "qux" } | { "op": "add", "path": "/foo/1", "value": "qux" } | |||
| ] | ] | |||
| The resulting JSON document: | The resulting JSON document: | |||
| { | { | |||
| "foo": [ "bar", "qux", "baz" ] | "foo": [ "bar", "qux", "baz" ] | |||
| } | } | |||
| A.3. Removing an Object Member | A.3. Removing an Object Member | |||
| An example target JSON document: | An example target JSON document: | |||
| { | { | |||
| "baz": "qux", | "baz": "qux", | |||
| "foo": "bar" | "foo": "bar" | |||
| } | } | |||
| A JSON Patch document: | A JSON Patch document: | |||
| [ | [ | |||
| { "op": "remove", "path": "/baz" } | { "op": "remove", "path": "/baz" } | |||
| ] | ] | |||
| The resulting JSON document: | The resulting JSON document: | |||
| { | { | |||
| "foo": "bar" | "foo": "bar" | |||
| } | } | |||
| A.4. Removing an Array Element | A.4. Removing an Array Element | |||
| An example target JSON document: | An example target JSON document: | |||
| { | { | |||
| "foo": [ "bar", "qux", "baz" ] | "foo": [ "bar", "qux", "baz" ] | |||
| } | } | |||
| A JSON Patch document: | A JSON Patch document: | |||
| [ | [ | |||
| { "op": "remove", "path": "/foo/1" } | { "op": "remove", "path": "/foo/1" } | |||
| ] | ] | |||
| The resulting JSON document: | The resulting JSON document: | |||
| { | { | |||
| "foo": [ "bar", "baz" ] | "foo": [ "bar", "baz" ] | |||
| } | } | |||
| A.5. Replacing a Value | A.5. Replacing a Value | |||
| An example target JSON document: | An example target JSON document: | |||
| { | { | |||
| "baz": "qux", | "baz": "qux", | |||
| "foo": "bar" | "foo": "bar" | |||
| } | } | |||
| A JSON Patch document: | A JSON Patch document: | |||
| [ | [ | |||
| { "op": "replace", "path": "/baz", "value": "boo" } | { "op": "replace", "path": "/baz", "value": "boo" } | |||
| ] | ] | |||
| The resulting JSON document: | The resulting JSON document: | |||
| { | { | |||
| "baz": "boo", | "baz": "boo", | |||
| "foo": "bar" | "foo": "bar" | |||
| } | } | |||
| A.6. Moving a Value | A.6. Moving a Value | |||
| An example target JSON document: | An example target JSON document: | |||
| { | { | |||
| "foo": { | "foo": { | |||
| "bar": "baz", | "bar": "baz", | |||
| "waldo": "fred" | "waldo": "fred" | |||
| } | } | |||
| "qux": { | "qux": { | |||
| "corge": "grault" | "corge": "grault" | |||
| } | } | |||
| } | } | |||
| A JSON Patch document: | A JSON Patch document: | |||
| [ | [ | |||
| { "op": "move", "path": "/foo/waldo", to: "/qux/thud" } | { "op": "move", "path": "/foo/waldo", to: "/qux/thud" } | |||
| ] | ] | |||
| The resulting JSON document: | The resulting JSON document: | |||
| { | { | |||
| "foo": { | "foo": { | |||
| "bar": "baz" | "bar": "baz" | |||
| } | } | |||
| "qux": { | "qux": { | |||
| "corge": "grault", | "corge": "grault", | |||
| "thud": "fred" | "thud": "fred" | |||
| } | } | |||
| } | } | |||
| A.7. Moving an Array Element | A.7. Moving an Array Element | |||
| An example target JSON document: | An example target JSON document: | |||
| { | { | |||
| "foo": [ "all", "grass", "cows", "eat" ] | "foo": [ "all", "grass", "cows", "eat" ] | |||
| } | } | |||
| A JSON Patch document: | A JSON Patch document: | |||
| [ | [ | |||
| { "op": "move", "path": "/foo/1", "to": "/foo/3" } | { "op": "move", "path": "/foo/1", "to": "/foo/3" } | |||
| ] | ] | |||
| The resulting JSON document: | The resulting JSON document: | |||
| { | { | |||
| "foo": [ "all", "cows", "eat", "grass" ] | "foo": [ "all", "cows", "eat", "grass" ] | |||
| } | } | |||
| 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 that will result in successful evaluation: | A JSON Patch document that will result in successful evaluation: | |||
| [ | [ | |||
| { "op": "test", "path": "/baz", "value": "qux" }, | { "op": "test", "path": "/baz", "value": "qux" }, | |||
| { "op": "test", "path": "/foo/1", "value": 2 } | { "op": "test", "path": "/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 that will result in an error condition: | A JSON Patch document that will result in an error condition: | |||
| [ | [ | |||
| { "op": "test", "path": "/baz", "value": "bar" } | { "op": "test", "path": "/baz", "value": "bar" } | |||
| ] | ] | |||
| A.10. Adding a nested Member Object | A.10. Adding a nested Member Object | |||
| An example target JSON document: | An example target JSON document: | |||
| { | { | |||
| "foo": "bar" | "foo": "bar" | |||
| } | } | |||
| A JSON Patch document: | A JSON Patch document: | |||
| [ | [ | |||
| { "op": "add", "path": "/child", "value": { "grandchild": { } } } | { "op": "add", "path": "/child", "value": { "grandchild": { } } } | |||
| ] | ] | |||
| The resulting JSON document: | The resulting JSON document: | |||
| { | { | |||
| "foo": "bar", | "foo": "bar", | |||
| "child": { | "child": { | |||
| "grandchild": { | "grandchild": { | |||
| } | } | |||
| } | } | |||
| } | } | |||
| A.11. Ignoring Unrecognized Elements | ||||
| An example target JSON document: | ||||
| { | ||||
| "foo":"bar" | ||||
| } | ||||
| A JSON Patch document: | ||||
| [ | ||||
| { "op":"add", "path":"/baz", "value":"qux", "xyz":123 } | ||||
| ] | ||||
| The resulting JSON document: | ||||
| { | ||||
| "foo":"bar", | ||||
| "baz":"qux" | ||||
| } | ||||
| A.12. Adding to a Non-existant Target | ||||
| An example target JSON document: | ||||
| { | ||||
| "foo": "bar" | ||||
| } | ||||
| A JSON Patch document: | ||||
| [ | ||||
| { "op": "add", "path": "/baz/bat", "value": "qux" } | ||||
| ] | ||||
| This JSON Patch document, applied to the target JSON document above, | ||||
| would result in an error (therefore not being applied) because the | ||||
| "add" operation's target location that references neither the root of | ||||
| the document, nor a member of an existing object, nor a member of an | ||||
| existing array. | ||||
| A.13. Invalid JSON Patch Document | ||||
| A JSON Patch document: | ||||
| [ | ||||
| { "op":"add", "path":"/baz", "value":"qux", "op":"remove" } | ||||
| ] | ||||
| This JSON Patch document cannot be treated as an "add" operation | ||||
| since there is a later "op":"remove" element. A JSON parser that | ||||
| hides such duplicate element names therefore cannot be used unless it | ||||
| always exposes only the last element with a given name (eg | ||||
| "op":"remove" in this example). | ||||
| 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) | |||
| End of changes. 56 change blocks. | ||||
| 86 lines changed or deleted | 151 lines changed or added | |||
This html diff was produced by rfcdiff 1.48. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ | ||||