idnits 2.17.00 (12 Aug 2021) /tmp/idnits32899/draft-ietf-appsawg-json-patch-00.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 (January 3, 2012) is 3790 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) ** 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 (~~), 1 warning (==), 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 US, Inc. 4 Intended status: Standards Track January 3, 2012 5 Expires: July 6, 2012 7 JSON Patch 8 draft-ietf-appsawg-json-patch-00 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 July 6, 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. test . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 59 5. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 6 60 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 6 61 7. Security Considerations . . . . . . . . . . . . . . . . . . . 7 62 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 7 63 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 7 64 9.1. Normative References . . . . . . . . . . . . . . . . . . . 7 65 9.2. Informative References . . . . . . . . . . . . . . . . . . 7 66 Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 8 67 A.1. Adding an Object Member . . . . . . . . . . . . . . . . . 8 68 A.2. Adding an Array Element . . . . . . . . . . . . . . . . . 8 69 A.3. Removing an Object Member . . . . . . . . . . . . . . . . 9 70 A.4. Removing an Array Element . . . . . . . . . . . . . . . . 9 71 A.5. Replacing a Value . . . . . . . . . . . . . . . . . . . . 10 72 A.6. Moving a Value . . . . . . . . . . . . . . . . . . . . . . 10 73 A.7. Moving an Array Element . . . . . . . . . . . . . . . . . 11 74 A.8. Testing a Value: Success . . . . . . . . . . . . . . . . . 11 75 A.9. Testing a Value: Error . . . . . . . . . . . . . . . . . . 12 76 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 12 78 1. Introduction 80 JavaScript Object Notation (JSON) [RFC4627] is a common format for 81 the exchange and storage of structured data. HTTP PATCH [RFC5789] 82 extends the Hypertext Transfer Protocol (HTTP) [RFC2616] with a 83 method to perform partial modifications to resources. 85 The JSON Patch media type "application/json-patch" is a JSON document 86 structure for expressing a sequence of operations to apply to a 87 target JSON document, suitable for use with the HTTP PATCH method. 89 2. Conventions 91 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 92 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 93 document are to be interpreted as described in RFC 2119 [RFC2119]. 95 3. Document Structure 97 A JSON Patch document contains a JSON array of objects. Each object 98 contains a single operation to apply to the target JSON document. 100 An example JSON Patch document: 102 [ 103 { "test": "/a/b/c", "value": "foo" }, 104 { "remove": "/a/b/c" }, 105 { "add": "/a/b/c", "value": [ "foo", "bar" ] }, 106 { "replace": "/a/b/c", "value": 42 }, 107 { "move": "/a/b/c", "to": "/a/b/d" } 108 ] 110 Evaluation of a JSON Patch document begins with a target JSON 111 document. Operations are applied sequentially in the order they 112 appear in the array. Each operation in the sequence is applied to 113 the target document; the resulting document becomes the target of the 114 next operation. Evaluation continues until all operations are 115 successfully applied or an error condition is encountered. 117 4. Operations 119 The operation to apply is expressed in a member of the operation 120 object. The name of the operation member is one of: "add", "remove", 121 "replace", "move" or "test". The member value is a string containing 122 a [JSON Pointer], which references the location within the target 123 document to apply the operation. It is an error condition if an 124 operation object contains no recognized operation member or more than 125 one operation member. 127 4.1. add 129 The "add" operation adds a new value at the specified location in the 130 target document. The location must reference one of: the root of the 131 target document, a member to add to an existing object, or an element 132 to add to an existing array. The operation object contains a "value" 133 member, which specifies the value to be added. 135 Example: 137 { "add": "/a/b/c", "value": [ "foo", "bar" ] } 139 If the location references the root of the target document or a 140 member of an existing object, it is an error condition if a value at 141 the specified location already exists. 143 If the location references an element of an existing array, any 144 elements at or above the specified index are shifted one position to 145 the right. It is an error condition if the specified index is 146 greater than the number of elements in the array. 148 4.2. remove 150 The "remove" operation removes the value at the specified location in 151 the target document. 153 Example: 155 { "remove": "/a/b/c" } 157 If removing an element from an array, any elements above the 158 specified index are shifted one position to the left. 160 It is an error condition if a value at the specified location does 161 not exist. 163 4.3. replace 165 The "replace" operation replaces the value at the specified location 166 in the target document with a new value. The operation object 167 contains a "value" member, which specifies the replacement value. 169 Example: 171 { "replace": "/a/b/c", "value": 42 } 173 This operation is functionally identical to expressing a "remove" 174 operation for a value, followed immediately by an "add" operation at 175 the same location with the replacement value. 177 It is an error condition if a value at the specified location does 178 not exist. 180 4.4. move 182 The "move" operation removes the value at one location and adds it to 183 another location in the target document. 185 The operation object contains a "to" member, a string containing a 186 JSON Pointer which references the location in the target document to 187 add the value to. This location must reference one of: the member to 188 add to an existing object, or an element to add to an existing array. 190 Example: 192 { "move": "/a/b/c", "to": "/a/b/d" } 194 This operation is functionally identical to expressing a "remove" 195 operation, followed immediately by an "add" operation at the new 196 location with the value that was just removed. 198 If the location in the "to" member references a member of an existing 199 object in the target document, it is an error condition if a value at 200 the specified location already exists. 202 If the location in the "to" member references an element of an 203 existing array, any elements at or above the specified index are 204 shifted one position to the right. It is an error condition if the 205 specified index is greater than the number of elements in the array. 207 4.5. test 209 The "test" operation tests that a value at the specified location in 210 the target document is equal to a specified value. The operation 211 object contains a "value" member, which specifies the value to test 212 for. 214 Example: 216 { "test": "/a/b/c", "value": "foo" } 217 It is an error condition if the value at the specified location is 218 not equal to the specified value. 220 5. Error Handling 222 If an error condition occurs, evaluation of the JSON Patch document 223 SHOULD terminate and application of the entire patch document SHALL 224 NOT be deemed successful. 226 6. IANA Considerations 228 The Internet media type for a JSON Patch document is application/ 229 json-patch. 231 Type name: application 233 Subtype name: json-patch 235 Required parameters: none 237 Optional parameters: none 239 Encoding considerations: binary 241 Security considerations: 242 See Security Considerations in section 7. 244 Interoperability considerations: N/A 246 Published specification: 247 draft-ietf-appsawg-json-patch-00 249 Applications that use this media type: 250 Applications that manipulate JSON documents. 252 Additional information: 254 Magic number(s): N/A 256 File extension(s): .json-patch 258 Macintosh file type code(s): TEXT 260 Person & email address to contact for further information: 261 Paul C. Bryan 263 Intended usage: COMMON 265 Restrictions on usage: none 267 Author: Paul C. Bryan 269 Change controller: Applications Area Working Group 271 7. Security Considerations 273 This specification has the same security considerations as JSON 274 [RFC4627] and JSON Pointer [JSON Pointer]. 276 8. Acknowledgements 278 The following individuals contributed ideas, feedback and wording, 279 which contributed to the content of this specification: 281 Mike Amundsen, Paul Davis, Dean Landolt, Randall Leeds, Mark 282 Nottingham, Julian Reschke, Eli Stevens. 284 The structure of a JSON Patch document was influenced by the XML 285 Patch document [RFC5261] specification. 287 9. References 289 9.1. Normative References 291 [JSON Pointer] 292 Bryan, P. and K. Zyp, "JSON Pointer", January 2012, . 295 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 296 Requirement Levels", BCP 14, RFC 2119, March 1997. 298 [RFC4627] Crockford, D., "The application/json Media Type for 299 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 301 9.2. Informative References 303 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 304 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 305 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 307 [RFC5261] Urpalainen, J., "An Extensible Markup Language (XML) Patch 308 Operations Framework Utilizing XML Path Language (XPath) 309 Selectors", RFC 5261, September 2008. 311 [RFC5789] Dusseault, L. and J. Snell, "PATCH Method for HTTP", 312 RFC 5789, March 2010. 314 Appendix A. Examples 316 A.1. Adding an Object Member 318 An example target JSON document: 320 { 321 "foo": "bar" 322 } 324 A JSON Patch document: 326 [ 327 { "add": "/baz", "value": "qux" } 328 ] 330 The resulting JSON document: 332 { 333 "baz": "qux", 334 "foo": "bar" 335 } 337 A.2. Adding an Array Element 339 An example target JSON document: 341 { 342 "foo": [ "bar", "baz" ] 343 } 345 A JSON Patch document: 347 [ 348 { "add": "/foo/1", "value": "qux" } 349 ] 351 The resulting JSON document: 353 { 354 "foo": [ "bar", "qux", "baz" ] 355 } 357 A.3. Removing an Object Member 359 An example target JSON document: 361 { 362 "baz": "qux", 363 "foo": "bar" 364 } 366 A JSON Patch document: 368 [ 369 { "remove": "/baz" } 370 ] 372 The resulting JSON document: 374 { 375 "foo": "bar" 376 } 378 A.4. Removing an Array Element 380 An example target JSON document: 382 { 383 "foo": [ "bar", "qux", "baz" ] 384 } 386 A JSON Patch document: 388 [ 389 { "remove": "/foo/1" } 390 ] 392 The resulting JSON document: 394 { 395 "foo": [ "bar", "baz" ] 396 } 398 A.5. Replacing a Value 400 An example target JSON document: 402 { 403 "baz": "qux", 404 "foo": "bar" 405 } 407 A JSON Patch document: 409 [ 410 { "replace": "/baz", "value": "boo" } 411 ] 413 The resulting JSON document: 415 { 416 "baz": "boo", 417 "foo": "bar" 418 } 420 A.6. Moving a Value 422 An example target JSON document: 424 { 425 "foo": { 426 "bar": "baz", 427 "waldo": "fred" 428 } 429 "qux": { 430 "corge": "grault" 431 } 432 } 434 A JSON Patch document: 436 [ 437 { "move": "/foo/waldo", to: "/qux/thud" } 438 ] 440 The resulting JSON document: 442 { 443 "foo": { 444 "bar": "baz" 445 } 446 "qux": { 447 "corge": "grault", 448 "thud": "fred" 449 } 450 } 452 A.7. Moving an Array Element 454 An example target JSON document: 456 { 457 "foo": [ "all", "grass", "cows", "eat" ] 458 } 460 A JSON Patch document: 462 [ 463 { "move": "/foo/1", "to": "/foo/3" } 464 ] 466 The resulting JSON document: 468 { 469 "foo": [ "all", "cows", "eat", "grass" ] 470 } 472 A.8. Testing a Value: Success 474 An example target JSON document: 476 { 477 "baz": "qux", 478 "foo": [ "a", 2, "c" ] 479 } 481 A JSON Patch document, which will result in successful evaluation: 483 [ 484 { "test": "/baz", "value": "qux" }, 485 { "test": "/foo/1", "value": 2 } 486 ] 488 A.9. Testing a Value: Error 490 An example target JSON document: 492 { 493 "baz": "qux" 494 } 496 A JSON Patch document, which will result in an error condition: 498 [ 499 { "test": "/baz", "value": "bar" } 500 ] 502 Author's Address 504 Paul C. Bryan (editor) 505 ForgeRock US, Inc. 506 201 NE Park Plaza Drive Suite 196 507 Vancouver, WA 98684 508 USA 510 Phone: +1 604 783 1481 511 Email: paul.bryan@forgerock.com