idnits 2.17.00 (12 Aug 2021) /tmp/idnits33692/draft-ietf-appsawg-json-patch-03.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 5, 2012) is 3544 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 9, 2013 September 5, 2012 7 JSON Patch 8 draft-ietf-appsawg-json-patch-03 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 9, 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 . . . . . . . . . . . . . . . . . . . . . 7 62 7. Security Considerations . . . . . . . . . . . . . . . . . . . 8 63 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 8 64 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 9 65 9.1. Normative References . . . . . . . . . . . . . . . . . . . 9 66 9.2. Informative References . . . . . . . . . . . . . . . . . . 9 67 Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 9 68 A.1. Adding an Object Member . . . . . . . . . . . . . . . . . 9 69 A.2. Adding an Array Element . . . . . . . . . . . . . . . . . 10 70 A.3. Removing an Object Member . . . . . . . . . . . . . . . . 10 71 A.4. Removing an Array Element . . . . . . . . . . . . . . . . 11 72 A.5. Replacing a Value . . . . . . . . . . . . . . . . . . . . 11 73 A.6. Moving a Value . . . . . . . . . . . . . . . . . . . . . . 11 74 A.7. Moving an Array Element . . . . . . . . . . . . . . . . . 12 75 A.8. Testing a Value: Success . . . . . . . . . . . . . . . . . 13 76 A.9. Testing a Value: Error . . . . . . . . . . . . . . . . . . 13 77 A.10. Adding a nested Member Object . . . . . . . . . . . . . . 13 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 4.2. remove 161 The "remove" operation removes the value at the specified location in 162 the target document. 164 Example: 166 { "remove": "/a/b/c" } 168 If removing an element from an array, any elements above the 169 specified index are shifted one position to the left. 171 It is an error condition if a value at the specified location does 172 not exist. 174 4.3. replace 176 The "replace" operation replaces the value at the specified location 177 in the target document with a new value. The operation object 178 contains a "value" member that specifies the replacement value. 180 Example: 182 { "replace": "/a/b/c", "value": 42 } 184 This operation is functionally identical to expressing a "remove" 185 operation for a value, followed immediately by an "add" operation at 186 the same location with the replacement value. 188 It is an error condition if a value at the specified location does 189 not exist. 191 4.4. move 193 The "move" operation removes the value at one location and adds it to 194 another location in the target document. 196 The operation object contains a "to" member, a string containing a 197 JSON Pointer value that references the location in the target 198 document to add the value to. This location must reference one of: 199 the member to add to an existing object, or an element to add to an 200 existing array. 202 Example: 204 { "move": "/a/b/c", "to": "/a/b/d" } 206 This operation is functionally identical to expressing a "remove" 207 operation, followed immediately by an "add" operation at the new 208 location with the value that was just removed. Moving a value to its 209 current location can be safely ignored. 211 If the location in the "to" member references a member of an existing 212 object in the target document, it is an error condition if a value at 213 the specified location already exists (unless "move" and "to" specify 214 the same object, which has no effect). 216 If the location in the "to" member references an element of an 217 existing array, any elements at or above the specified index are 218 shifted one position to the right. It is an error condition if the 219 specified index is greater than the number of elements in the array. 221 4.5. copy 223 The "copy" operation copies the value at one location to another 224 location in the target document. 226 The operation object contains a "to" member, a string containing a 227 JSON Pointer value that references the location in the target 228 document to add the value to. This location must reference one of: 229 the member to add to an existing object, or an element to add to an 230 existing array. 232 Example: 234 { "copy": "/a/b/c", "to": "/a/b/e" } 236 If the location in the "to" member references a member of an existing 237 object in the target document, it is an error condition if a value at 238 the specified location already exists. 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. It is an error condition if the 243 specified index is greater than the number of elements in the array. 245 4.6. test 247 The "test" operation tests that a value at the specified location in 248 the target document is equal to a specified value. The operation 249 object contains a "value" member that specifies the value to test 250 for. 252 Here, "equal" means that the target and specified values are of the 253 same JSON type, and considered equal by the following rules for that 254 type: 256 o strings: are considered equal if, after unescaping any sequence(s) 257 in both strings starting with a reverse solidus, they contain the 258 same number of Unicode characters and their code points are 259 position-wise equal. 261 o numbers: are considered equal if subtracting one from the other 262 results in 0. 264 o arrays: are considered equal if they contain the same number of 265 values, and each value can be considered equal to the value at the 266 corresponding position in the other array. 268 o objects: are considered equal if they contain the same number of 269 members, and each member can be considered equal to a member in 270 the other object, by comparing their keys as strings, and values 271 using this list of type-specific rules. 273 o literals (false, true and null): are considered equal if they are 274 the same. 276 Note that this is a logical comparison; e.g., whitespace between the 277 member values of an array is not significant. 279 Also, note that ordering of the serialisation of object members is 280 not significant. 282 Example: 284 { "test": "/a/b/c", "value": "foo" } 286 It is an error condition if the value at the specified location is 287 not equal to the specified value. 289 5. Error Handling 291 If an error condition occurs, evaluation of the JSON Patch document 292 SHOULD terminate and application of the entire patch document SHALL 293 NOT be deemed successful. Note that as per [RFC5789], PATCH is 294 atomic. 296 6. IANA Considerations 298 The Internet media type for a JSON Patch document is application/ 299 json-patch. 301 Type name: application 303 Subtype name: json-patch 305 Required parameters: none 307 Optional parameters: none 309 Encoding considerations: binary 310 Security considerations: 311 See Security Considerations in section 7. 313 Interoperability considerations: N/A 315 Published specification: 316 [this memo] 318 Applications that use this media type: 319 Applications that manipulate JSON documents. 321 Additional information: 323 Magic number(s): N/A 325 File extension(s): .json-patch 327 Macintosh file type code(s): TEXT 329 Person & email address to contact for further information: 330 Paul C. Bryan 332 Intended usage: COMMON 334 Restrictions on usage: none 336 Author: Paul C. Bryan 338 Change controller: IETF 340 7. Security Considerations 342 This specification has the same security considerations as JSON 343 [RFC4627] and [JSON-Pointer]. 345 8. Acknowledgements 347 The following individuals contributed ideas, feedback and wording to 348 this specification: 350 Mike Acar, Mike Amundsen, Paul Davis, Murray S. Kucherawy, Dean 351 Landolt, Randall Leeds, Julian Reschke, Eli Stevens. 353 The structure of a JSON Patch document was influenced by the XML 354 Patch document [RFC5261] specification. 356 9. References 358 9.1. Normative References 360 [JSON-Pointer] 361 Bryan, P. and K. Zyp, "JSON Pointer", 362 draft-ietf-appsawg-json-pointer-01 (work in progress), 363 March 2012. 365 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 366 Requirement Levels", BCP 14, RFC 2119, March 1997. 368 [RFC4627] Crockford, D., "The application/json Media Type for 369 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 371 9.2. Informative References 373 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 374 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 375 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 377 [RFC5261] Urpalainen, J., "An Extensible Markup Language (XML) Patch 378 Operations Framework Utilizing XML Path Language (XPath) 379 Selectors", RFC 5261, September 2008. 381 [RFC5789] Dusseault, L. and J. Snell, "PATCH Method for HTTP", 382 RFC 5789, March 2010. 384 Appendix A. Examples 386 A.1. Adding an Object Member 388 An example target JSON document: 390 { 391 "foo": "bar" 392 } 394 A JSON Patch document: 396 [ 397 { "add": "/baz", "value": "qux" } 398 ] 400 The resulting JSON document: 402 { 403 "baz": "qux", 404 "foo": "bar" 405 } 407 A.2. Adding an Array Element 409 An example target JSON document: 411 { 412 "foo": [ "bar", "baz" ] 413 } 415 A JSON Patch document: 417 [ 418 { "add": "/foo/1", "value": "qux" } 419 ] 421 The resulting JSON document: 423 { 424 "foo": [ "bar", "qux", "baz" ] 425 } 427 A.3. Removing an Object Member 429 An example target JSON document: 431 { 432 "baz": "qux", 433 "foo": "bar" 434 } 436 A JSON Patch document: 438 [ 439 { "remove": "/baz" } 440 ] 442 The resulting JSON document: 444 { 445 "foo": "bar" 446 } 448 A.4. Removing an Array Element 450 An example target JSON document: 452 { 453 "foo": [ "bar", "qux", "baz" ] 454 } 456 A JSON Patch document: 458 [ 459 { "remove": "/foo/1" } 460 ] 462 The resulting JSON document: 464 { 465 "foo": [ "bar", "baz" ] 466 } 468 A.5. Replacing a Value 470 An example target JSON document: 472 { 473 "baz": "qux", 474 "foo": "bar" 475 } 477 A JSON Patch document: 479 [ 480 { "replace": "/baz", "value": "boo" } 481 ] 483 The resulting JSON document: 485 { 486 "baz": "boo", 487 "foo": "bar" 488 } 490 A.6. Moving a Value 492 An example target JSON document: 494 { 495 "foo": { 496 "bar": "baz", 497 "waldo": "fred" 498 } 499 "qux": { 500 "corge": "grault" 501 } 502 } 504 A JSON Patch document: 506 [ 507 { "move": "/foo/waldo", to: "/qux/thud" } 508 ] 510 The resulting JSON document: 512 { 513 "foo": { 514 "bar": "baz" 515 } 516 "qux": { 517 "corge": "grault", 518 "thud": "fred" 519 } 520 } 522 A.7. Moving an Array Element 524 An example target JSON document: 526 { 527 "foo": [ "all", "grass", "cows", "eat" ] 528 } 530 A JSON Patch document: 532 [ 533 { "move": "/foo/1", "to": "/foo/3" } 534 ] 536 The resulting JSON document: 538 { 539 "foo": [ "all", "cows", "eat", "grass" ] 540 } 542 A.8. Testing a Value: Success 544 An example target JSON document: 546 { 547 "baz": "qux", 548 "foo": [ "a", 2, "c" ] 549 } 551 A JSON Patch document that will result in successful evaluation: 553 [ 554 { "test": "/baz", "value": "qux" }, 555 { "test": "/foo/1", "value": 2 } 556 ] 558 A.9. Testing a Value: Error 560 An example target JSON document: 562 { 563 "baz": "qux" 564 } 566 A JSON Patch document that will result in an error condition: 568 [ 569 { "test": "/baz", "value": "bar" } 570 ] 572 A.10. Adding a nested Member Object 574 An example target JSON document: 576 { 577 "foo": "bar" 578 } 580 A JSON Patch document: 582 [ 583 { "add": "/child", "value": { "grandchild": { } } } 584 ] 586 The resulting JSON document: 588 { 589 "foo": "bar", 590 "child": { 591 "grandchild": { 592 } 593 } 594 } 596 Authors' Addresses 598 Paul C. Bryan (editor) 599 Salesforce.com 601 Phone: +1 604 783 1481 602 Email: pbryan@anode.ca 604 Mark Nottingham (editor) 606 Email: mnot@mnot.net