idnits 2.17.00 (12 Aug 2021) /tmp/idnits36947/draft-ietf-appsawg-json-patch-06.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 (October 22, 2012) is 3497 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: April 25, 2013 October 22, 2012 7 JSON Patch 8 draft-ietf-appsawg-json-patch-06 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 April 25, 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 . . . . . . . . . . . . . . . . . . . . . . . . . . 4 54 4.1. add . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 55 4.2. remove . . . . . . . . . . . . . . . . . . . . . . . . . . 5 56 4.3. replace . . . . . . . . . . . . . . . . . . . . . . . . . 5 57 4.4. move . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 58 4.5. copy . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 59 4.6. test . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 60 5. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 8 61 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 8 62 7. Security Considerations . . . . . . . . . . . . . . . . . . . 9 63 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 9 64 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 10 65 9.1. Normative References . . . . . . . . . . . . . . . . . . . 10 66 9.2. Informative References . . . . . . . . . . . . . . . . . . 10 67 Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 10 68 A.1. Adding an Object Member . . . . . . . . . . . . . . . . . 10 69 A.2. Adding an Array Element . . . . . . . . . . . . . . . . . 11 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 . . . . . . . . . . . . . . . . . 14 76 A.9. Testing a Value: Error . . . . . . . . . . . . . . . . . . 14 77 A.10. Adding a nested Member Object . . . . . . . . . . . . . . 14 78 A.11. Ignoring Unrecognized Elements . . . . . . . . . . . . . . 15 79 A.12. Adding to a Non-existant Target . . . . . . . . . . . . . 15 80 A.13. Invalid JSON Patch Document . . . . . . . . . . . . . . . 16 81 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 16 83 1. Introduction 85 JavaScript Object Notation (JSON) [RFC4627] is a common format for 86 the exchange and storage of structured data. HTTP PATCH [RFC5789] 87 extends the Hypertext Transfer Protocol (HTTP) [RFC2616] with a 88 method to perform partial modifications to resources. 90 JSON Patch is a format (identified by the media type "application/ 91 json-patch") for expressing a sequence of operations to apply to a 92 target JSON document, suitable for use with the HTTP PATCH method. 94 2. Conventions 96 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 97 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 98 document are to be interpreted as described in RFC 2119 [RFC2119]. 100 See Section 5 for information about handling errors. 102 3. Document Structure 104 A JSON Patch document is a JSON [RFC4627] document whose root is an 105 array of objects. Each object represents a single operation to be 106 applied to the target JSON document. 108 An example JSON Patch document: 110 [ 111 { "op": "test", "path": "/a/b/c", "value": "foo" }, 112 { "op": "remove", "path": "/a/b/c" }, 113 { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] }, 114 { "op": "replace", "path": "/a/b/c", "value": 42 }, 115 { "op": "move", "path": "/a/b/c", "to": "/a/b/d" }, 116 { "op": "copy", "path": "/a/b/d", "to": "/a/b/e" } 117 ] 119 Evaluation of a JSON Patch document begins with a target JSON 120 document. Operations are applied sequentially in the order they 121 appear in the array. Each operation in the sequence is applied to 122 the target document; the resulting document becomes the target of the 123 next operation. Evaluation continues until all operations are 124 successfully applied, or an error condition is encountered. 126 4. Operations 128 Operation objects MUST have exactly one "op" member, whose value 129 indicates the operation to perform. Its value MUST be one of "add", 130 "remove", "replace", "move", "copy" or "test". The semantics of each 131 is defined below. 133 Additionally, operation objects MUST have exactly one "path" member, 134 whose value MUST be a string containing a [JSON-Pointer] value that 135 references the location within the target document to perform the 136 operation (the "target location"). 138 Other members of operation objects MUST be ignored, unless they are 139 explicitly allowed by the definition of the operation. 141 Note that the ordering of members in JSON objects is not significant; 142 therefore, the following operations are equivalent: 144 { "op": "add", "path": "/a/b/c", "value": "foo" } 145 { "path": "/a/b/c", "op": "add", "value": "foo" } 146 { "value": "foo", "path": "/a/b/c", "op": "add" } 148 4.1. add 150 The "add" operation adds a new value at the target location. The 151 operation object MUST contain a "value" member that specifies the 152 value to be added. 154 When the operation is applied, the target location MUST reference one 155 of: 157 o the root of the target document, 159 o a member to add to an existing object, or 161 o an element to add to an existing array. 163 For example: 165 { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] } 167 If the target location references an element of an existing array, 168 any elements at or above the specified index are shifted one position 169 to the right. The specified index MUST NOT be greater than the 170 number of elements in the array. 172 When the "-" character is used to index the end of the array, this 173 has the effect of appending the value to the array. 175 Note that this operation will, in common use, have a target location 176 that does not resolve to an existing value, resulting in the 177 pointer's error handling algorithm being invoked. This specification 178 defines the error handling algorithm for "add" pointers to explicitly 179 ignore the error and perform the operation as specified. 181 4.2. remove 183 The "remove" operation removes the value at the target location. 185 The target location MUST exist for the operation to be successful. 187 For example: 189 { "op": "remove", "path": "/a/b/c" } 191 If removing an element from an array, any elements above the 192 specified index are shifted one position to the left. 194 4.3. replace 196 The "replace" operation replaces the value at the target location 197 with a new value. The operation object MUST contain a "value" member 198 that specifies the replacement value. 200 The target location MUST exist for the operation to be successful. 202 For example: 204 { "op": "replace", "path": "/a/b/c", "value": 42 } 206 This operation is functionally identical to expressing a "remove" 207 operation for a value, followed immediately by an "add" operation at 208 the same location with the replacement value. 210 4.4. move 212 The "move" operation removes the value at the target location and 213 adds it to another location. 215 The operation object MUST contain a "to" member, a string containing 216 a JSON Pointer value that references the location in the target 217 document to add the value to. 219 The "to" location MUST reference one of: 221 o the member to add to an existing object, or 222 o an element to add to an existing array. 224 For example: 226 { "op": "move", "path": "/a/b/c", "to": "/a/b/d" } 228 This operation is functionally identical to expressing a "remove" 229 operation on the target location, followed immediately by an "add" 230 operation at the "to" location with the value that was just removed. 232 The location in the "to" member MUST NOT be part of the location 233 defined by "path"; i.e., a location cannot be moved into one of its 234 children. 236 The location in the "to" member MUST NOT reference a member of an 237 existing object in the target document, unless "path" and "to" 238 specify the same object, which has no effect. 240 If the location in the "to" member references an element of an 241 existing array, any elements at or above the specified index are 242 shifted one position to the right. The specified index MUST NOT be 243 greater than the number of elements in the array. 245 4.5. copy 247 The "copy" operation copies the value at the target location to 248 another location. 250 The operation object MUST contain a "to" member, a string containing 251 a JSON Pointer value that references the location in the target 252 document to add the value to. 254 This location MUST reference one of: 256 o the member to add to an existing object, or 258 o an element to add to an existing array. 260 For example: 262 { "op": "copy", "path": "/a/b/c", "to": "/a/b/e" } 264 The location in the "to" member MUST NOT be part of the location 265 defined by "path"; i.e., a location cannot be copied into one of its 266 children. 268 The location in the "to" member MUST NOT reference a member of an 269 existing object in the target document, unless "path" and "to" 270 specify the same object, which has no effect. 272 If the location in the "to" member references an element of an 273 existing array, any elements at or above the specified index are 274 shifted one position to the right. The specified index MUST NOT be 275 greater than the number of elements in the array. 277 4.6. test 279 The "test" operation tests that a value at the target location is 280 equal to a specified value. 282 The operation object MUST contain a "value" member that conveys the 283 value to be compared to that at the target location. 285 The target location MUST be equal to the "value" value for the 286 operation to be considered successful. 288 Here, "equal" means that the value at the target location and the 289 value conveyed by "value" are of the same JSON type, and considered 290 equal by the following rules for that type: 292 o strings: are considered equal if, after unescaping any sequence(s) 293 in both strings starting with a reverse solidus, they contain the 294 same number of Unicode characters and their code points are 295 position-wise equal. 297 o numbers: are considered equal if subtracting one from the other 298 results in 0. 300 o arrays: are considered equal if they contain the same number of 301 values, and each value can be considered equal to the value at the 302 corresponding position in the other array. 304 o objects: are considered equal if they contain the same number of 305 members, and each member can be considered equal to a member in 306 the other object, by comparing their keys as strings, and values 307 using this list of type-specific rules. 309 o literals (false, true and null): are considered equal if they are 310 the same. 312 Note that this is a logical comparison; e.g., whitespace between the 313 member values of an array is not significant. 315 Also, note that ordering of the serialisation of object members is 316 not significant. 318 For example: 320 { "op": "test", "path": "/a/b/c", "value": "foo" } 322 5. Error Handling 324 If a RFC2119 [RFC2119] requirement is violated by a JSON Patch 325 document, or if an operation is not successful, evaluation of the 326 JSON Patch document SHOULD terminate and application of the entire 327 patch document SHALL NOT be deemed successful. 329 See [RFC5789], Section 2.2 for considerations regarding handling 330 errors when JSON Patch is used with the HTTP PATCH method, including 331 suggested status codes to use to indicate various conditions. 333 Note that as per [RFC5789], when used with the PATCH HTTP method, it 334 is atomic. Therefore, the following patch would result in no changes 335 being made to the document at all (because the "test" operation 336 results in an error). 338 [ 339 { "op": "replace", "path": "/a/b/c", "value": 42 }, 340 { "op": "test", "path": "/a/b/c", "value": "C" } 341 ] 343 6. IANA Considerations 345 The Internet media type for a JSON Patch document is application/ 346 json-patch. 348 Type name: application 350 Subtype name: json-patch 352 Required parameters: none 354 Optional parameters: none 356 Encoding considerations: binary 358 Security considerations: 359 See Security Considerations in section 7. 361 Interoperability considerations: N/A 363 Published specification: 364 [this memo] 366 Applications that use this media type: 367 Applications that manipulate JSON documents. 369 Additional information: 371 Magic number(s): N/A 373 File extension(s): .json-patch 375 Macintosh file type code(s): TEXT 377 Person & email address to contact for further information: 378 Paul C. Bryan 380 Intended usage: COMMON 382 Restrictions on usage: none 384 Author: Paul C. Bryan 386 Change controller: IETF 388 7. Security Considerations 390 This specification has the same security considerations as JSON 391 [RFC4627] and [JSON-Pointer]. 393 8. Acknowledgements 395 The following individuals contributed ideas, feedback and wording to 396 this specification: 398 Mike Acar, Mike Amundsen, Paul Davis, Murray S. Kucherawy, Dean 399 Landolt, Randall Leeds, James Manger, Julian Reschke, James Snell, 400 Eli Stevens. 402 The structure of a JSON Patch document was influenced by the XML 403 Patch document [RFC5261] specification. 405 9. References 406 9.1. Normative References 408 [JSON-Pointer] 409 Bryan, P. and K. Zyp, "JSON Pointer", 410 draft-ietf-appsawg-json-pointer-04 (work in progress), 411 March 2012. 413 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 414 Requirement Levels", BCP 14, RFC 2119, March 1997. 416 [RFC4627] Crockford, D., "The application/json Media Type for 417 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 419 9.2. Informative References 421 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 422 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 423 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 425 [RFC5261] Urpalainen, J., "An Extensible Markup Language (XML) Patch 426 Operations Framework Utilizing XML Path Language (XPath) 427 Selectors", RFC 5261, September 2008. 429 [RFC5789] Dusseault, L. and J. Snell, "PATCH Method for HTTP", 430 RFC 5789, March 2010. 432 Appendix A. Examples 434 A.1. Adding an Object Member 436 An example target JSON document: 438 { 439 "foo": "bar" 440 } 442 A JSON Patch document: 444 [ 445 { "op": "add", "path": "/baz", "value": "qux" } 446 ] 448 The resulting JSON document: 450 { 451 "baz": "qux", 452 "foo": "bar" 454 } 456 A.2. Adding an Array Element 458 An example target JSON document: 460 { 461 "foo": [ "bar", "baz" ] 462 } 464 A JSON Patch document: 466 [ 467 { "op": "add", "path": "/foo/1", "value": "qux" } 468 ] 470 The resulting JSON document: 472 { 473 "foo": [ "bar", "qux", "baz" ] 474 } 476 A.3. Removing an Object Member 478 An example target JSON document: 480 { 481 "baz": "qux", 482 "foo": "bar" 483 } 485 A JSON Patch document: 487 [ 488 { "op": "remove", "path": "/baz" } 489 ] 491 The resulting JSON document: 493 { 494 "foo": "bar" 495 } 497 A.4. Removing an Array Element 499 An example target JSON document: 501 { 502 "foo": [ "bar", "qux", "baz" ] 503 } 505 A JSON Patch document: 507 [ 508 { "op": "remove", "path": "/foo/1" } 509 ] 511 The resulting JSON document: 513 { 514 "foo": [ "bar", "baz" ] 515 } 517 A.5. Replacing a Value 519 An example target JSON document: 521 { 522 "baz": "qux", 523 "foo": "bar" 524 } 526 A JSON Patch document: 528 [ 529 { "op": "replace", "path": "/baz", "value": "boo" } 530 ] 532 The resulting JSON document: 534 { 535 "baz": "boo", 536 "foo": "bar" 537 } 539 A.6. Moving a Value 541 An example target JSON document: 543 { 544 "foo": { 545 "bar": "baz", 546 "waldo": "fred" 547 } 548 "qux": { 549 "corge": "grault" 550 } 551 } 553 A JSON Patch document: 555 [ 556 { "op": "move", "path": "/foo/waldo", to: "/qux/thud" } 557 ] 559 The resulting JSON document: 561 { 562 "foo": { 563 "bar": "baz" 564 } 565 "qux": { 566 "corge": "grault", 567 "thud": "fred" 568 } 569 } 571 A.7. Moving an Array Element 573 An example target JSON document: 575 { 576 "foo": [ "all", "grass", "cows", "eat" ] 577 } 579 A JSON Patch document: 581 [ 582 { "op": "move", "path": "/foo/1", "to": "/foo/3" } 583 ] 585 The resulting JSON document: 587 { 588 "foo": [ "all", "cows", "eat", "grass" ] 589 } 591 A.8. Testing a Value: Success 593 An example target JSON document: 595 { 596 "baz": "qux", 597 "foo": [ "a", 2, "c" ] 598 } 600 A JSON Patch document that will result in successful evaluation: 602 [ 603 { "op": "test", "path": "/baz", "value": "qux" }, 604 { "op": "test", "path": "/foo/1", "value": 2 } 605 ] 607 A.9. Testing a Value: Error 609 An example target JSON document: 611 { 612 "baz": "qux" 613 } 615 A JSON Patch document that will result in an error condition: 617 [ 618 { "op": "test", "path": "/baz", "value": "bar" } 619 ] 621 A.10. Adding a nested Member Object 623 An example target JSON document: 625 { 626 "foo": "bar" 627 } 629 A JSON Patch document: 631 [ 632 { "op": "add", "path": "/child", "value": { "grandchild": { } } } 633 ] 635 The resulting JSON document: 637 { 638 "foo": "bar", 639 "child": { 640 "grandchild": { 641 } 642 } 643 } 645 A.11. Ignoring Unrecognized Elements 647 An example target JSON document: 649 { 650 "foo":"bar" 651 } 653 A JSON Patch document: 655 [ 656 { "op":"add", "path":"/baz", "value":"qux", "xyz":123 } 657 ] 659 The resulting JSON document: 661 { 662 "foo":"bar", 663 "baz":"qux" 664 } 666 A.12. Adding to a Non-existant Target 668 An example target JSON document: 670 { 671 "foo": "bar" 672 } 674 A JSON Patch document: 676 [ 677 { "op": "add", "path": "/baz/bat", "value": "qux" } 678 ] 680 This JSON Patch document, applied to the target JSON document above, 681 would result in an error (therefore not being applied) because the 682 "add" operation's target location that references neither the root of 683 the document, nor a member of an existing object, nor a member of an 684 existing array. 686 A.13. Invalid JSON Patch Document 688 A JSON Patch document: 690 [ 691 { "op":"add", "path":"/baz", "value":"qux", "op":"remove" } 692 ] 694 This JSON Patch document cannot be treated as an "add" operation 695 since there is a later "op":"remove" element. A JSON parser that 696 hides such duplicate element names therefore cannot be used unless it 697 always exposes only the last element with a given name (eg 698 "op":"remove" in this example). 700 Authors' Addresses 702 Paul C. Bryan (editor) 703 Salesforce.com 705 Phone: +1 604 783 1481 706 Email: pbryan@anode.ca 708 Mark Nottingham (editor) 710 Email: mnot@mnot.net