idnits 2.17.00 (12 Aug 2021) /tmp/idnits33206/draft-ietf-appsawg-json-patch-04.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (September 17, 2012) is 3532 days in the past. Is this intentional? Checking references for intended status: Informational ---------------------------------------------------------------------------- == Outdated reference: draft-ietf-appsawg-json-pointer has been published as RFC 6901 ** Obsolete normative reference: RFC 4627 (Obsoleted by RFC 7158, RFC 7159) -- Obsolete informational reference (is this intentional?): RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) Summary: 1 error (**), 0 flaws (~~), 2 warnings (==), 2 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Applications Area Working Group P. Bryan, Ed. 3 Internet-Draft Salesforce.com 4 Intended status: Informational M. Nottingham, Ed. 5 Expires: March 21, 2013 September 17, 2012 7 JSON Patch 8 draft-ietf-appsawg-json-patch-04 10 Abstract 12 JSON Patch defines the media type "application/json-patch", a JSON 13 document structure for expressing a sequence of operations to apply 14 to a JSON document. 16 Status of this Memo 18 This Internet-Draft is submitted in full conformance with the 19 provisions of BCP 78 and BCP 79. 21 Internet-Drafts are working documents of the Internet Engineering 22 Task Force (IETF). Note that other groups may also distribute 23 working documents as Internet-Drafts. The list of current Internet- 24 Drafts is at http://datatracker.ietf.org/drafts/current/. 26 Internet-Drafts are draft documents valid for a maximum of six months 27 and may be updated, replaced, or obsoleted by other documents at any 28 time. It is inappropriate to use Internet-Drafts as reference 29 material or to cite them other than as "work in progress." 31 This Internet-Draft will expire on March 21, 2013. 33 Copyright Notice 35 Copyright (c) 2012 IETF Trust and the persons identified as the 36 document authors. All rights reserved. 38 This document is subject to BCP 78 and the IETF Trust's Legal 39 Provisions Relating to IETF Documents 40 (http://trustee.ietf.org/license-info) in effect on the date of 41 publication of this document. Please review these documents 42 carefully, as they describe your rights and restrictions with respect 43 to this document. Code Components extracted from this document must 44 include Simplified BSD License text as described in Section 4.e of 45 the Trust Legal Provisions and are provided without warranty as 46 described in the Simplified BSD License. 48 Table of Contents 50 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 51 2. Conventions . . . . . . . . . . . . . . . . . . . . . . . . . 3 52 3. Document Structure . . . . . . . . . . . . . . . . . . . . . . 3 53 4. Operations . . . . . . . . . . . . . . . . . . . . . . . . . . 3 54 4.1. add . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 55 4.2. remove . . . . . . . . . . . . . . . . . . . . . . . . . . 4 56 4.3. replace . . . . . . . . . . . . . . . . . . . . . . . . . 5 57 4.4. move . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 58 4.5. copy . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 59 4.6. test . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 60 5. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 7 61 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 8 62 7. Security Considerations . . . . . . . . . . . . . . . . . . . 9 63 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 9 64 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 9 65 9.1. Normative References . . . . . . . . . . . . . . . . . . . 9 66 9.2. Informative References . . . . . . . . . . . . . . . . . . 9 67 Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 10 68 A.1. Adding an Object Member . . . . . . . . . . . . . . . . . 10 69 A.2. Adding an Array Element . . . . . . . . . . . . . . . . . 10 70 A.3. Removing an Object Member . . . . . . . . . . . . . . . . 11 71 A.4. Removing an Array Element . . . . . . . . . . . . . . . . 11 72 A.5. Replacing a Value . . . . . . . . . . . . . . . . . . . . 12 73 A.6. Moving a Value . . . . . . . . . . . . . . . . . . . . . . 12 74 A.7. Moving an Array Element . . . . . . . . . . . . . . . . . 13 75 A.8. Testing a Value: Success . . . . . . . . . . . . . . . . . 13 76 A.9. Testing a Value: Error . . . . . . . . . . . . . . . . . . 14 77 A.10. Adding a nested Member Object . . . . . . . . . . . . . . 14 78 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 14 80 1. Introduction 82 JavaScript Object Notation (JSON) [RFC4627] is a common format for 83 the exchange and storage of structured data. HTTP PATCH [RFC5789] 84 extends the Hypertext Transfer Protocol (HTTP) [RFC2616] with a 85 method to perform partial modifications to resources. 87 The JSON Patch media type "application/json-patch" is a JSON document 88 structure for expressing a sequence of operations to apply to a 89 target JSON document, suitable for use with the HTTP PATCH method. 91 2. Conventions 93 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 94 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 95 document are to be interpreted as described in RFC 2119 [RFC2119]. 97 3. Document Structure 99 A JSON Patch document contains a JSON array of objects. Each object 100 contains a single operation to apply to the target JSON document. 102 An example JSON Patch document: 104 [ 105 { "test": "/a/b/c", "value": "foo" }, 106 { "remove": "/a/b/c" }, 107 { "add": "/a/b/c", "value": [ "foo", "bar" ] }, 108 { "replace": "/a/b/c", "value": 42 }, 109 { "move": "/a/b/c", "to": "/a/b/d" }, 110 { "copy": "/a/b/c", "to": "/a/b/e" } 111 ] 113 Evaluation of a JSON Patch document begins with a target JSON 114 document. Operations are applied sequentially in the order they 115 appear in the array. Each operation in the sequence is applied to 116 the target document; the resulting document becomes the target of the 117 next operation. Evaluation continues until all operations are 118 successfully applied or an error condition is encountered. 120 4. Operations 122 The operation to perform is expressed in a member of the operation 123 object. The name of the operation member is one of: "add", "remove", 124 "replace", "move", "copy" or "test". 126 The member value is a string containing a [JSON-Pointer] value that 127 references the location within the target document to perform the 128 operation. It is an error condition if an operation object contains 129 no recognized operation member or more than one operation member. 131 4.1. add 133 The "add" operation adds a new value at the specified location in the 134 target document. The location must reference one of: the root of the 135 target document, a member to add to an existing object, or an element 136 to add to an existing array. The operation object contains a "value" 137 member that specifies the value to be added. 139 Example: 141 { "add": "/a/b/c", "value": [ "foo", "bar" ] } 143 If the location references the root of the target document or a 144 member of an existing object, it is an error condition if a value at 145 the specified location already exists. 147 If the location references an element of an existing array, any 148 elements at or above the specified index are shifted one position to 149 the right. It is an error condition if the specified index is 150 greater than the number of elements in the array. 152 Note that this operation will, in common use, contain a JSON Pointer 153 that does not resolve to an existing value in the target document. 154 As such, the pointer's error handling algorithm is invoked. This 155 specification defines the error handling algorithm for "add" pointers 156 to explicitly ignore the error and perform the operation as 157 specified. 159 It is an error condition if the "value" member is not present. 161 4.2. remove 163 The "remove" operation removes the value at the specified location in 164 the target document. 166 Example: 168 { "remove": "/a/b/c" } 170 If removing an element from an array, any elements above the 171 specified index are shifted one position to the left. 173 It is an error condition if a value at the specified location does 174 not exist. 176 4.3. replace 178 The "replace" operation replaces the value at the specified location 179 in the target document with a new value. The operation object 180 contains a "value" member that specifies the replacement value. 182 Example: 184 { "replace": "/a/b/c", "value": 42 } 186 This operation is functionally identical to expressing a "remove" 187 operation for a value, followed immediately by an "add" operation at 188 the same location with the replacement value. 190 It is an error condition if a value at the specified location does 191 not exist. 193 It is an error condition if the "value" member is not present. 195 4.4. move 197 The "move" operation removes the value at one location and adds it to 198 another location in the target document. 200 The operation object contains a "to" member, a string containing a 201 JSON Pointer value that references the location in the target 202 document to add the value to. This location must reference one of: 203 the member to add to an existing object, or an element to add to an 204 existing array. 206 Example: 208 { "move": "/a/b/c", "to": "/a/b/d" } 210 This operation is functionally identical to expressing a "remove" 211 operation, followed immediately by an "add" operation at the new 212 location with the value that was just removed. Moving a value to its 213 current location can be safely ignored. 215 If the location in the "to" member references a member of an existing 216 object in the target document, it is an error condition if a value at 217 the specified location already exists (unless "move" and "to" specify 218 the same object, which has no effect). 220 If the location in the "to" member references an element of an 221 existing array, any elements at or above the specified index are 222 shifted one position to the right. It is an error condition if the 223 specified index is greater than the number of elements in the array. 225 It is an error condition if the "to" member is not present. 227 4.5. copy 229 The "copy" operation copies the value at one location to another 230 location in the target document. 232 The operation object contains a "to" member, a string containing a 233 JSON Pointer value that references the location in the target 234 document to add the value to. This location must reference one of: 235 the member to add to an existing object, or an element to add to an 236 existing array. 238 Example: 240 { "copy": "/a/b/c", "to": "/a/b/e" } 242 If the location in the "to" member references a member of an existing 243 object in the target document, it is an error condition if a value at 244 the specified location already exists. 246 If the location in the "to" member references an element of an 247 existing array, any elements at or above the specified index are 248 shifted one position to the right. It is an error condition if the 249 specified index is greater than the number of elements in the array. 251 It is an error condition if the "to" member is not present. 253 4.6. test 255 The "test" operation tests that a value at the specified location in 256 the target document is equal to a specified value. The operation 257 object contains a "value" member that specifies the value to test 258 for. 260 Here, "equal" means that the target and specified values are of the 261 same JSON type, and considered equal by the following rules for that 262 type: 264 o strings: are considered equal if, after unescaping any sequence(s) 265 in both strings starting with a reverse solidus, they contain the 266 same number of Unicode characters and their code points are 267 position-wise equal. 269 o numbers: are considered equal if subtracting one from the other 270 results in 0. 272 o arrays: are considered equal if they contain the same number of 273 values, and each value can be considered equal to the value at the 274 corresponding position in the other array. 276 o objects: are considered equal if they contain the same number of 277 members, and each member can be considered equal to a member in 278 the other object, by comparing their keys as strings, and values 279 using this list of type-specific rules. 281 o literals (false, true and null): are considered equal if they are 282 the same. 284 Note that this is a logical comparison; e.g., whitespace between the 285 member values of an array is not significant. 287 Also, note that ordering of the serialisation of object members is 288 not significant. 290 Example: 292 { "test": "/a/b/c", "value": "foo" } 294 It is an error condition if the value at the specified location is 295 not equal to the specified value. 297 If the value is not specified, the test is only for presence, not 298 value. 300 For example: 302 { "test": "/a/b/c" } 304 merely tests that the indicated structure is present in the target 305 document. 307 5. Error Handling 309 If an error condition occurs, evaluation of the JSON Patch document 310 SHOULD terminate and application of the entire patch document SHALL 311 NOT be deemed successful. Note that as per [RFC5789], when used with 312 the PATCH HTTP method, it is atomic. 314 Therefore, the following patch would result in no changes being made 315 to the document at all (because the "test" operation results in an 316 error). 318 [ 319 {"replace": "/a/b/c", "value": 42}, 320 {"test": "/a/b/c", "value": "C"} 321 ] 323 6. IANA Considerations 325 The Internet media type for a JSON Patch document is application/ 326 json-patch. 328 Type name: application 330 Subtype name: json-patch 332 Required parameters: none 334 Optional parameters: none 336 Encoding considerations: binary 338 Security considerations: 339 See Security Considerations in section 7. 341 Interoperability considerations: N/A 343 Published specification: 344 [this memo] 346 Applications that use this media type: 347 Applications that manipulate JSON documents. 349 Additional information: 351 Magic number(s): N/A 353 File extension(s): .json-patch 355 Macintosh file type code(s): TEXT 357 Person & email address to contact for further information: 358 Paul C. Bryan 360 Intended usage: COMMON 362 Restrictions on usage: none 364 Author: Paul C. Bryan 366 Change controller: IETF 368 7. Security Considerations 370 This specification has the same security considerations as JSON 371 [RFC4627] and [JSON-Pointer]. 373 8. Acknowledgements 375 The following individuals contributed ideas, feedback and wording to 376 this specification: 378 Mike Acar, Mike Amundsen, Paul Davis, Murray S. Kucherawy, Dean 379 Landolt, Randall Leeds, Julian Reschke, James Snell, Eli Stevens. 381 The structure of a JSON Patch document was influenced by the XML 382 Patch document [RFC5261] specification. 384 9. References 386 9.1. Normative References 388 [JSON-Pointer] 389 Bryan, P. and K. Zyp, "JSON Pointer", 390 draft-ietf-appsawg-json-pointer-04 (work in progress), 391 March 2012. 393 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 394 Requirement Levels", BCP 14, RFC 2119, March 1997. 396 [RFC4627] Crockford, D., "The application/json Media Type for 397 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 399 9.2. Informative References 401 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 402 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 403 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 405 [RFC5261] Urpalainen, J., "An Extensible Markup Language (XML) Patch 406 Operations Framework Utilizing XML Path Language (XPath) 407 Selectors", RFC 5261, September 2008. 409 [RFC5789] Dusseault, L. and J. Snell, "PATCH Method for HTTP", 410 RFC 5789, March 2010. 412 Appendix A. Examples 414 A.1. Adding an Object Member 416 An example target JSON document: 418 { 419 "foo": "bar" 420 } 422 A JSON Patch document: 424 [ 425 { "add": "/baz", "value": "qux" } 426 ] 428 The resulting JSON document: 430 { 431 "baz": "qux", 432 "foo": "bar" 433 } 435 A.2. Adding an Array Element 437 An example target JSON document: 439 { 440 "foo": [ "bar", "baz" ] 441 } 443 A JSON Patch document: 445 [ 446 { "add": "/foo/1", "value": "qux" } 447 ] 449 The resulting JSON document: 451 { 452 "foo": [ "bar", "qux", "baz" ] 453 } 455 A.3. Removing an Object Member 457 An example target JSON document: 459 { 460 "baz": "qux", 461 "foo": "bar" 462 } 464 A JSON Patch document: 466 [ 467 { "remove": "/baz" } 468 ] 470 The resulting JSON document: 472 { 473 "foo": "bar" 474 } 476 A.4. Removing an Array Element 478 An example target JSON document: 480 { 481 "foo": [ "bar", "qux", "baz" ] 482 } 484 A JSON Patch document: 486 [ 487 { "remove": "/foo/1" } 488 ] 490 The resulting JSON document: 492 { 493 "foo": [ "bar", "baz" ] 494 } 496 A.5. Replacing a Value 498 An example target JSON document: 500 { 501 "baz": "qux", 502 "foo": "bar" 503 } 505 A JSON Patch document: 507 [ 508 { "replace": "/baz", "value": "boo" } 509 ] 511 The resulting JSON document: 513 { 514 "baz": "boo", 515 "foo": "bar" 516 } 518 A.6. Moving a Value 520 An example target JSON document: 522 { 523 "foo": { 524 "bar": "baz", 525 "waldo": "fred" 526 } 527 "qux": { 528 "corge": "grault" 529 } 530 } 532 A JSON Patch document: 534 [ 535 { "move": "/foo/waldo", to: "/qux/thud" } 536 ] 538 The resulting JSON document: 540 { 541 "foo": { 542 "bar": "baz" 543 } 544 "qux": { 545 "corge": "grault", 546 "thud": "fred" 547 } 548 } 550 A.7. Moving an Array Element 552 An example target JSON document: 554 { 555 "foo": [ "all", "grass", "cows", "eat" ] 556 } 558 A JSON Patch document: 560 [ 561 { "move": "/foo/1", "to": "/foo/3" } 562 ] 564 The resulting JSON document: 566 { 567 "foo": [ "all", "cows", "eat", "grass" ] 568 } 570 A.8. Testing a Value: Success 572 An example target JSON document: 574 { 575 "baz": "qux", 576 "foo": [ "a", 2, "c" ] 577 } 579 A JSON Patch document that will result in successful evaluation: 581 [ 582 { "test": "/baz", "value": "qux" }, 583 { "test": "/foo/1", "value": 2 } 584 ] 586 A.9. Testing a Value: Error 588 An example target JSON document: 590 { 591 "baz": "qux" 592 } 594 A JSON Patch document that will result in an error condition: 596 [ 597 { "test": "/baz", "value": "bar" } 598 ] 600 A.10. Adding a nested Member Object 602 An example target JSON document: 604 { 605 "foo": "bar" 606 } 608 A JSON Patch document: 610 [ 611 { "add": "/child", "value": { "grandchild": { } } } 612 ] 614 The resulting JSON document: 616 { 617 "foo": "bar", 618 "child": { 619 "grandchild": { 620 } 621 } 622 } 624 Authors' Addresses 626 Paul C. Bryan (editor) 627 Salesforce.com 629 Phone: +1 604 783 1481 630 Email: pbryan@anode.ca 631 Mark Nottingham (editor) 633 Email: mnot@mnot.net