idnits 2.17.00 (12 Aug 2021) /tmp/idnits35064/draft-ietf-appsawg-json-patch-01.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 (March 9, 2012) is 3724 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 ForgeRock 4 Intended status: Informational March 9, 2012 5 Expires: September 10, 2012 7 JSON Patch 8 draft-ietf-appsawg-json-patch-01 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 September 10, 2012. 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 . . . . . . . . . . . . . . . . . . . . . . . . . 4 57 4.4. move . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 58 4.5. copy . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 59 4.6. test . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 60 5. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 6 61 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 6 62 7. Security Considerations . . . . . . . . . . . . . . . . . . . 7 63 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 7 64 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 8 65 9.1. Normative References . . . . . . . . . . . . . . . . . . . 8 66 9.2. Informative References . . . . . . . . . . . . . . . . . . 8 67 Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 8 68 A.1. Adding an Object Member . . . . . . . . . . . . . . . . . 8 69 A.2. Adding an Array Element . . . . . . . . . . . . . . . . . 9 70 A.3. Removing an Object Member . . . . . . . . . . . . . . . . 9 71 A.4. Removing an Array Element . . . . . . . . . . . . . . . . 10 72 A.5. Replacing a Value . . . . . . . . . . . . . . . . . . . . 10 73 A.6. Moving a Value . . . . . . . . . . . . . . . . . . . . . . 11 74 A.7. Moving an Array Element . . . . . . . . . . . . . . . . . 11 75 A.8. Testing a Value: Success . . . . . . . . . . . . . . . . . 12 76 A.9. Testing a Value: Error . . . . . . . . . . . . . . . . . . 12 77 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 12 79 1. Introduction 81 JavaScript Object Notation (JSON) [RFC4627] is a common format for 82 the exchange and storage of structured data. HTTP PATCH [RFC5789] 83 extends the Hypertext Transfer Protocol (HTTP) [RFC2616] with a 84 method to perform partial modifications to resources. 86 The JSON Patch media type "application/json-patch" is a JSON document 87 structure for expressing a sequence of operations to apply to a 88 target JSON document, suitable for use with the HTTP PATCH method. 90 2. Conventions 92 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 93 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 94 document are to be interpreted as described in RFC 2119 [RFC2119]. 96 3. Document Structure 98 A JSON Patch document contains a JSON array of objects. Each object 99 contains a single operation to apply to the target JSON document. 101 An example JSON Patch document: 103 [ 104 { "test": "/a/b/c", "value": "foo" }, 105 { "remove": "/a/b/c" }, 106 { "add": "/a/b/c", "value": [ "foo", "bar" ] }, 107 { "replace": "/a/b/c", "value": 42 }, 108 { "move": "/a/b/c", "to": "/a/b/d" }, 109 { "copy": "/a/b/c", "to": "/a/b/e" } 110 ] 112 Evaluation of a JSON Patch document begins with a target JSON 113 document. Operations are applied sequentially in the order they 114 appear in the array. Each operation in the sequence is applied to 115 the target document; the resulting document becomes the target of the 116 next operation. Evaluation continues until all operations are 117 successfully applied or an error condition is encountered. 119 4. Operations 121 The operation to perform is expressed in a member of the operation 122 object. The name of the operation member is one of: "add", "remove", 123 "replace", "move", "copy" or "test". The member value is a string 124 containing a [JSON-Pointer] value, which references the location 125 within the target document to perform the operation. It is an error 126 condition if an operation object contains no recognized operation 127 member or more than one operation member. 129 4.1. add 131 The "add" operation adds a new value at the specified location in the 132 target document. The location must reference one of: the root of the 133 target document, a member to add to an existing object, or an element 134 to add to an existing array. The operation object contains a "value" 135 member, which specifies the value to be added. 137 Example: 139 { "add": "/a/b/c", "value": [ "foo", "bar" ] } 141 If the location references the root of the target document or a 142 member of an existing object, it is an error condition if a value at 143 the specified location already exists. 145 If the location references an element of an existing array, any 146 elements at or above the specified index are shifted one position to 147 the right. It is an error condition if the specified index is 148 greater than the number of elements in the array. 150 4.2. remove 152 The "remove" operation removes the value at the specified location in 153 the target document. 155 Example: 157 { "remove": "/a/b/c" } 159 If removing an element from an array, any elements above the 160 specified index are shifted one position to the left. 162 It is an error condition if a value at the specified location does 163 not exist. 165 4.3. replace 167 The "replace" operation replaces the value at the specified location 168 in the target document with a new value. The operation object 169 contains a "value" member, which specifies the replacement value. 171 Example: 173 { "replace": "/a/b/c", "value": 42 } 175 This operation is functionally identical to expressing a "remove" 176 operation for a value, followed immediately by an "add" operation at 177 the same location with the replacement value. 179 It is an error condition if a value at the specified location does 180 not exist. 182 4.4. move 184 The "move" operation removes the value at one location and adds it to 185 another location in the target document. 187 The operation object contains a "to" member, a string containing a 188 JSON Pointer value, which references the location in the target 189 document to add the value to. This location must reference one of: 190 the member to add to an existing object, or an element to add to an 191 existing array. 193 Example: 195 { "move": "/a/b/c", "to": "/a/b/d" } 197 This operation is functionally identical to expressing a "remove" 198 operation, followed immediately by an "add" operation at the new 199 location with the value that was just removed. Moving a value to its 200 current location can be safely ignored. 202 If the location in the "to" member references a member of an existing 203 object in the target document, it is an error condition if a value at 204 the specified location already exists. 206 If the location in the "to" member references an element of an 207 existing array, any elements at or above the specified index are 208 shifted one position to the right. It is an error condition if the 209 specified index is greater than the number of elements in the array. 211 4.5. copy 213 The "copy" operation copies the value at one location to another 214 location in the target document. 216 The operation object contains a "to" member, a string containing a 217 JSON Pointer value, which references the location in the target 218 document to add the value to. This location must reference one of: 220 the member to add to an existing object, or an element to add to an 221 existing array. 223 Example: 225 { "copy": "/a/b/c", "to": "/a/b/e" } 227 If the location in the "to" member references a member of an existing 228 object in the target document, it is an error condition if a value at 229 the specified location already exists. 231 If the location in the "to" member references an element of an 232 existing array, any elements at or above the specified index are 233 shifted one position to the right. It is an error condition if the 234 specified index is greater than the number of elements in the array. 236 4.6. test 238 The "test" operation tests that a value at the specified location in 239 the target document is equal to a specified value. The operation 240 object contains a "value" member, which specifies the value to test 241 for. If values are or contain objects or arrays, they must be 242 identical (i.e. same order of elements, with the same values). 244 Example: 246 { "test": "/a/b/c", "value": "foo" } 248 It is an error condition if the value at the specified location is 249 not equal to the specified value. 251 5. Error Handling 253 If an error condition occurs, evaluation of the JSON Patch document 254 SHOULD terminate and application of the entire patch document SHALL 255 NOT be deemed successful. 257 6. IANA Considerations 259 The Internet media type for a JSON Patch document is application/ 260 json-patch. 262 Type name: application 263 Subtype name: json-patch 265 Required parameters: none 267 Optional parameters: none 269 Encoding considerations: binary 271 Security considerations: 272 See Security Considerations in section 7. 274 Interoperability considerations: N/A 276 Published specification: 277 [this memo] 279 Applications that use this media type: 280 Applications that manipulate JSON documents. 282 Additional information: 284 Magic number(s): N/A 286 File extension(s): .json-patch 288 Macintosh file type code(s): TEXT 290 Person & email address to contact for further information: 291 Paul C. Bryan 293 Intended usage: COMMON 295 Restrictions on usage: none 297 Author: Paul C. Bryan 299 Change controller: IETF 301 7. Security Considerations 303 This specification has the same security considerations as JSON 304 [RFC4627] and [JSON-Pointer]. 306 8. Acknowledgements 308 The following individuals contributed ideas, feedback and wording, 309 which contributed to the content of this specification: 311 Mike Acar, Mike Amundsen, Paul Davis, Murray S. Kucherawy, Dean 312 Landolt, Randall Leeds, Mark Nottingham, Julian Reschke, Eli 313 Stevens. 315 The structure of a JSON Patch document was influenced by the XML 316 Patch document [RFC5261] specification. 318 9. References 320 9.1. Normative References 322 [JSON-Pointer] 323 Bryan, P. and K. Zyp, "JSON Pointer", 324 draft-ietf-appsawg-json-pointer-01 (work in progress), 325 March 2012. 327 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 328 Requirement Levels", BCP 14, RFC 2119, March 1997. 330 [RFC4627] Crockford, D., "The application/json Media Type for 331 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 333 9.2. Informative References 335 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 336 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 337 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 339 [RFC5261] Urpalainen, J., "An Extensible Markup Language (XML) Patch 340 Operations Framework Utilizing XML Path Language (XPath) 341 Selectors", RFC 5261, September 2008. 343 [RFC5789] Dusseault, L. and J. Snell, "PATCH Method for HTTP", 344 RFC 5789, March 2010. 346 Appendix A. Examples 348 A.1. Adding an Object Member 350 An example target JSON document: 352 { 353 "foo": "bar" 354 } 355 A JSON Patch document: 357 [ 358 { "add": "/baz", "value": "qux" } 359 ] 361 The resulting JSON document: 363 { 364 "baz": "qux", 365 "foo": "bar" 366 } 368 A.2. Adding an Array Element 370 An example target JSON document: 372 { 373 "foo": [ "bar", "baz" ] 374 } 376 A JSON Patch document: 378 [ 379 { "add": "/foo/1", "value": "qux" } 380 ] 382 The resulting JSON document: 384 { 385 "foo": [ "bar", "qux", "baz" ] 386 } 388 A.3. Removing an Object Member 390 An example target JSON document: 392 { 393 "baz": "qux", 394 "foo": "bar" 395 } 397 A JSON Patch document: 399 [ 400 { "remove": "/baz" } 401 ] 402 The resulting JSON document: 404 { 405 "foo": "bar" 406 } 408 A.4. Removing an Array Element 410 An example target JSON document: 412 { 413 "foo": [ "bar", "qux", "baz" ] 414 } 416 A JSON Patch document: 418 [ 419 { "remove": "/foo/1" } 420 ] 422 The resulting JSON document: 424 { 425 "foo": [ "bar", "baz" ] 426 } 428 A.5. Replacing a Value 430 An example target JSON document: 432 { 433 "baz": "qux", 434 "foo": "bar" 435 } 437 A JSON Patch document: 439 [ 440 { "replace": "/baz", "value": "boo" } 441 ] 443 The resulting JSON document: 445 { 446 "baz": "boo", 447 "foo": "bar" 448 } 450 A.6. Moving a Value 452 An example target JSON document: 454 { 455 "foo": { 456 "bar": "baz", 457 "waldo": "fred" 458 } 459 "qux": { 460 "corge": "grault" 461 } 462 } 464 A JSON Patch document: 466 [ 467 { "move": "/foo/waldo", to: "/qux/thud" } 468 ] 470 The resulting JSON document: 472 { 473 "foo": { 474 "bar": "baz" 475 } 476 "qux": { 477 "corge": "grault", 478 "thud": "fred" 479 } 480 } 482 A.7. Moving an Array Element 484 An example target JSON document: 486 { 487 "foo": [ "all", "grass", "cows", "eat" ] 488 } 490 A JSON Patch document: 492 [ 493 { "move": "/foo/1", "to": "/foo/3" } 494 ] 496 The resulting JSON document: 498 { 499 "foo": [ "all", "cows", "eat", "grass" ] 500 } 502 A.8. Testing a Value: Success 504 An example target JSON document: 506 { 507 "baz": "qux", 508 "foo": [ "a", 2, "c" ] 509 } 511 A JSON Patch document, which will result in successful evaluation: 513 [ 514 { "test": "/baz", "value": "qux" }, 515 { "test": "/foo/1", "value": 2 } 516 ] 518 A.9. Testing a Value: Error 520 An example target JSON document: 522 { 523 "baz": "qux" 524 } 526 A JSON Patch document, which will result in an error condition: 528 [ 529 { "test": "/baz", "value": "bar" } 530 ] 532 Author's Address 534 Paul C. Bryan (editor) 535 ForgeRock 537 Phone: +1 604 783 1481 538 Email: pbryan@anode.ca