idnits 2.17.1 draft-ietf-appsawg-json-patch-05.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 26, 2012) is 4231 days in the past. Is this intentional? Checking references for intended status: Informational ---------------------------------------------------------------------------- == Outdated reference: A later version (-09) exists of draft-ietf-appsawg-json-pointer-04 ** 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 30, 2013 September 26, 2012 7 JSON Patch 8 draft-ietf-appsawg-json-patch-05 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 30, 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 . . . . . . . . . . . . . . . . . . . . . . . . . . 9 65 9.1. Normative References . . . . . . . . . . . . . . . . . . . 9 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 . . . . . . . . . . . . . . . . . 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 JSON Patch is a format (identified by the media type "application/ 88 json-patch") 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 See Section 5 for information about handling errors. 99 3. Document Structure 101 A JSON Patch document is a JSON [RFC4627] document whose root object 102 is an array of objects. Each object represents a single operation to 103 be applied to the target JSON document. 105 An example JSON Patch document: 107 [ 108 { "op": "test", "path": "/a/b/c", "value": "foo" }, 109 { "op": "remove", "path": "/a/b/c" }, 110 { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] }, 111 { "op": "replace", "path": "/a/b/c", "value": 42 }, 112 { "op": "move", "path": "/a/b/c", "to": "/a/b/d" }, 113 { "op": "copy", "path": "/a/b/c", "to": "/a/b/e" } 114 ] 116 Evaluation of a JSON Patch document begins with a target JSON 117 document. Operations are applied sequentially in the order they 118 appear in the array. Each operation in the sequence is applied to 119 the target document; the resulting document becomes the target of the 120 next operation. Evaluation continues until all operations are 121 successfully applied, or an error condition is encountered. 123 4. Operations 125 Operation objects MUST have exactly one "op" member, whose value 126 indicates the operation to perform. Its value MUST be one of "add", 127 "remove", "replace", "move", "copy" or "test". The semantics of each 128 is defined below. 130 Additionally, operation objects MUST have exactly one "path" member, 131 whose value MUST be a string containing a [JSON-Pointer] value that 132 references the location within the target document to perform the 133 operation (the "target location"). 135 Other members of operation objects MUST be ignored, unless they are 136 explicitly allowed by the definition of the operation. 138 Note that the ordering of members in JSON objects is not significant; 139 therefore, the following operations are equivalent: 141 { "op": "add", "path": "/a/b/c", "value": "foo" } 142 { "path": "/a/b/c", "op": "add", "value": "foo" } 143 { "value": "foo", "path": "/a/b/c", "op": "add" } 145 4.1. add 147 The "add" operation adds a new value at the target location. The 148 operation object MUST contain a "value" member that specifies the 149 value to be added. 151 When the operation is applied, the target location MUST reference one 152 of: 154 o the root of the target document, 156 o a member to add to an existing object, or 158 o an element to add to an existing array. 160 For example: 162 { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] } 164 If the target location references the root of the target document or 165 a member of an existing object, the specified location MUST already 166 exist for the operation to be successful. 168 If the target location references an element of an existing array, 169 any elements at or above the specified index are shifted one position 170 to the right. The specified index MUST NOT be greater than the 171 number of elements in the array. 173 Note that this operation will, in common use, have a target location 174 that does not resolve to an existing value, resulting in the 175 pointer's error handling algorithm being invoked. This specification 176 defines the error handling algorithm for "add" pointers to explicitly 177 ignore the error and perform the operation as specified. 179 4.2. remove 181 The "remove" operation removes the value at the specified location. 183 The value at the specified location MUST exist for the operation to 184 be successful. 186 For example: 188 { "op": "remove", "path": "/a/b/c" } 190 If removing an element from an array, any elements above the 191 specified index are shifted one position to the left. 193 4.3. replace 195 The "replace" operation replaces the value at the specified location 196 with a new value. The operation object MUST contain a "value" member 197 that specifies the replacement value. 199 The value at the specified location MUST exist for the operation to 200 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 specified location and 213 adds it to another location in the target document. 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 223 o an element to add to an existing array. 225 For example: 227 { "op": "move", "path": "/a/b/c", "to": "/a/b/d" } 229 This operation is functionally identical to expressing a "remove" 230 operation on the specified location, followed immediately by an "add" 231 operation at the "to" location with the value that was just removed. 233 The location in the "to" member MUST NOT reference a member of an 234 existing object in the target document, unless "move" and "to" 235 specify the same object, which has no effect. 237 If the location in the "to" member references an element of an 238 existing array, any elements at or above the specified index are 239 shifted one position to the right. The specified index MUST NOT be 240 greater than the number of elements in the array. 242 4.5. copy 244 The "copy" operation copies the value at the specified location to 245 another location in the target document. 247 The operation object MUST contain a "to" member, a string containing 248 a JSON Pointer value that references the location in the target 249 document to add the value to. 251 This location MUST reference one of: 253 o the member to add to an existing object, or 255 o an element to add to an existing array. 257 For example: 259 { "op": "copy", "path": "/a/b/c", "to": "/a/b/e" } 261 The location in the "to" member MUST NOT reference a member of an 262 existing object in the target document, unless "move" and "to" 263 specify the same object, which has no effect. 265 If the location in the "to" member references an element of an 266 existing array, any elements at or above the specified index are 267 shifted one position to the right. The specified index MUST NOT be 268 greater than the number of elements in the array. 270 4.6. test 272 The "test" operation tests that a value at the specified location is 273 equal to a value. 275 The operation object MUST contain a "value" member that conveys the 276 value to be compared to that at the specified location. 278 The value at the specified location MUST be equal to the specified 279 value for the operation to be considered successful. 281 Here, "equal" means that the value at the specified location and the 282 value conveyed by "value" are of the same JSON type, and considered 283 equal by the following rules for that type: 285 o strings: are considered equal if, after unescaping any sequence(s) 286 in both strings starting with a reverse solidus, they contain the 287 same number of Unicode characters and their code points are 288 position-wise equal. 290 o numbers: are considered equal if subtracting one from the other 291 results in 0. 293 o arrays: are considered equal if they contain the same number of 294 values, and each value can be considered equal to the value at the 295 corresponding position in the other array. 297 o objects: are considered equal if they contain the same number of 298 members, and each member can be considered equal to a member in 299 the other object, by comparing their keys as strings, and values 300 using this list of type-specific rules. 302 o literals (false, true and null): are considered equal if they are 303 the same. 305 Note that this is a logical comparison; e.g., whitespace between the 306 member values of an array is not significant. 308 Also, note that ordering of the serialisation of object members is 309 not significant. 311 For example: 313 { "op": "test", "path": "/a/b/c", "value": "foo" } 315 5. Error Handling 317 If a RFC2119 [RFC2119] requirement is violated by a JSON Patch 318 document, or if an operation is not successful, evaluation of the 319 JSON Patch document SHOULD terminate and application of the entire 320 patch document SHALL NOT be deemed successful. 322 See [RFC5789], Section 2.2 for considerations regarding handling 323 errors when JSON Patch is used with the HTTP PATCH method, including 324 suggested status codes to use to indicate various conditions. 326 Note that as per [RFC5789], when used with the PATCH HTTP method, it 327 is atomic. Therefore, the following patch would result in no changes 328 being made to the document at all (because the "test" operation 329 results in an error). 331 [ 332 { "op": "replace", "path": "/a/b/c", "value": 42 }, 333 { "op": "test", "path": "/a/b/c", "value": "C" } 334 ] 336 6. IANA Considerations 338 The Internet media type for a JSON Patch document is application/ 339 json-patch. 341 Type name: application 343 Subtype name: json-patch 345 Required parameters: none 347 Optional parameters: none 349 Encoding considerations: binary 351 Security considerations: 352 See Security Considerations in section 7. 354 Interoperability considerations: N/A 356 Published specification: 357 [this memo] 359 Applications that use this media type: 360 Applications that manipulate JSON documents. 362 Additional information: 364 Magic number(s): N/A 366 File extension(s): .json-patch 368 Macintosh file type code(s): TEXT 370 Person & email address to contact for further information: 371 Paul C. Bryan 373 Intended usage: COMMON 375 Restrictions on usage: none 377 Author: Paul C. Bryan 379 Change controller: IETF 381 7. Security Considerations 383 This specification has the same security considerations as JSON 384 [RFC4627] and [JSON-Pointer]. 386 8. Acknowledgements 388 The following individuals contributed ideas, feedback and wording to 389 this specification: 391 Mike Acar, Mike Amundsen, Paul Davis, Murray S. Kucherawy, Dean 392 Landolt, Randall Leeds, James Manger, Julian Reschke, James Snell, 393 Eli Stevens. 395 The structure of a JSON Patch document was influenced by the XML 396 Patch document [RFC5261] specification. 398 9. References 400 9.1. Normative References 402 [JSON-Pointer] 403 Bryan, P. and K. Zyp, "JSON Pointer", 404 draft-ietf-appsawg-json-pointer-04 (work in progress), 405 March 2012. 407 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 408 Requirement Levels", BCP 14, RFC 2119, March 1997. 410 [RFC4627] Crockford, D., "The application/json Media Type for 411 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 413 9.2. Informative References 415 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 416 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 417 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 419 [RFC5261] Urpalainen, J., "An Extensible Markup Language (XML) Patch 420 Operations Framework Utilizing XML Path Language (XPath) 421 Selectors", RFC 5261, September 2008. 423 [RFC5789] Dusseault, L. and J. Snell, "PATCH Method for HTTP", 424 RFC 5789, March 2010. 426 Appendix A. Examples 428 A.1. Adding an Object Member 430 An example target JSON document: 432 { 433 "foo": "bar" 434 } 436 A JSON Patch document: 438 [ 439 { "op": "add", "path": "/baz", "value": "qux" } 440 ] 442 The resulting JSON document: 444 { 445 "baz": "qux", 446 "foo": "bar" 447 } 449 A.2. Adding an Array Element 451 An example target JSON document: 453 { 454 "foo": [ "bar", "baz" ] 455 } 457 A JSON Patch document: 459 [ 460 { "op": "add", "path": "/foo/1", "value": "qux" } 461 ] 463 The resulting JSON document: 465 { 466 "foo": [ "bar", "qux", "baz" ] 467 } 469 A.3. Removing an Object Member 471 An example target JSON document: 473 { 474 "baz": "qux", 475 "foo": "bar" 476 } 478 A JSON Patch document: 480 [ 481 { "op": "remove", "path": "/baz" } 482 ] 484 The resulting JSON document: 486 { 487 "foo": "bar" 488 } 490 A.4. Removing an Array Element 492 An example target JSON document: 494 { 495 "foo": [ "bar", "qux", "baz" ] 496 } 497 A JSON Patch document: 499 [ 500 { "op": "remove", "path": "/foo/1" } 501 ] 503 The resulting JSON document: 505 { 506 "foo": [ "bar", "baz" ] 507 } 509 A.5. Replacing a Value 511 An example target JSON document: 513 { 514 "baz": "qux", 515 "foo": "bar" 516 } 518 A JSON Patch document: 520 [ 521 { "op": "replace", "path": "/baz", "value": "boo" } 522 ] 524 The resulting JSON document: 526 { 527 "baz": "boo", 528 "foo": "bar" 529 } 531 A.6. Moving a Value 533 An example target JSON document: 535 { 536 "foo": { 537 "bar": "baz", 538 "waldo": "fred" 539 } 540 "qux": { 541 "corge": "grault" 542 } 543 } 544 A JSON Patch document: 546 [ 547 { "op": "move", "path": "/foo/waldo", to: "/qux/thud" } 548 ] 550 The resulting JSON document: 552 { 553 "foo": { 554 "bar": "baz" 555 } 556 "qux": { 557 "corge": "grault", 558 "thud": "fred" 559 } 560 } 562 A.7. Moving an Array Element 564 An example target JSON document: 566 { 567 "foo": [ "all", "grass", "cows", "eat" ] 568 } 570 A JSON Patch document: 572 [ 573 { "op": "move", "path": "/foo/1", "to": "/foo/3" } 574 ] 576 The resulting JSON document: 578 { 579 "foo": [ "all", "cows", "eat", "grass" ] 580 } 582 A.8. Testing a Value: Success 584 An example target JSON document: 586 { 587 "baz": "qux", 588 "foo": [ "a", 2, "c" ] 589 } 591 A JSON Patch document that will result in successful evaluation: 593 [ 594 { "op": "test", "path": "/baz", "value": "qux" }, 595 { "op": "test", "path": "/foo/1", "value": 2 } 596 ] 598 A.9. Testing a Value: Error 600 An example target JSON document: 602 { 603 "baz": "qux" 604 } 606 A JSON Patch document that will result in an error condition: 608 [ 609 { "op": "test", "path": "/baz", "value": "bar" } 610 ] 612 A.10. Adding a nested Member Object 614 An example target JSON document: 616 { 617 "foo": "bar" 618 } 620 A JSON Patch document: 622 [ 623 { "op": "add", "path": "/child", "value": { "grandchild": { } } } 624 ] 626 The resulting JSON document: 628 { 629 "foo": "bar", 630 "child": { 631 "grandchild": { 632 } 633 } 634 } 636 Authors' Addresses 638 Paul C. Bryan (editor) 639 Salesforce.com 641 Phone: +1 604 783 1481 642 Email: pbryan@anode.ca 644 Mark Nottingham (editor) 646 Email: mnot@mnot.net