idnits 2.17.1 draft-ietf-appsawg-json-patch-02.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 (July 4, 2012) is 4286 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-01 ** 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 M. Nottingham, Ed. 5 Expires: January 5, 2013 Rackspace 6 July 4, 2012 8 JSON Patch 9 draft-ietf-appsawg-json-patch-02 11 Abstract 13 JSON Patch defines the media type "application/json-patch", a JSON 14 document structure for expressing a sequence of operations to apply 15 to a JSON document. 17 Status of this Memo 19 This Internet-Draft is submitted in full conformance with the 20 provisions of BCP 78 and BCP 79. 22 Internet-Drafts are working documents of the Internet Engineering 23 Task Force (IETF). Note that other groups may also distribute 24 working documents as Internet-Drafts. The list of current Internet- 25 Drafts is at http://datatracker.ietf.org/drafts/current/. 27 Internet-Drafts are draft documents valid for a maximum of six months 28 and may be updated, replaced, or obsoleted by other documents at any 29 time. It is inappropriate to use Internet-Drafts as reference 30 material or to cite them other than as "work in progress." 32 This Internet-Draft will expire on January 5, 2013. 34 Copyright Notice 36 Copyright (c) 2012 IETF Trust and the persons identified as the 37 document authors. All rights reserved. 39 This document is subject to BCP 78 and the IETF Trust's Legal 40 Provisions Relating to IETF Documents 41 (http://trustee.ietf.org/license-info) in effect on the date of 42 publication of this document. Please review these documents 43 carefully, as they describe your rights and restrictions with respect 44 to this document. Code Components extracted from this document must 45 include Simplified BSD License text as described in Section 4.e of 46 the Trust Legal Provisions and are provided without warranty as 47 described in the Simplified BSD License. 49 Table of Contents 51 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 52 2. Conventions . . . . . . . . . . . . . . . . . . . . . . . . . 3 53 3. Document Structure . . . . . . . . . . . . . . . . . . . . . . 3 54 4. Operations . . . . . . . . . . . . . . . . . . . . . . . . . . 3 55 4.1. add . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 56 4.2. remove . . . . . . . . . . . . . . . . . . . . . . . . . . 4 57 4.3. replace . . . . . . . . . . . . . . . . . . . . . . . . . 5 58 4.4. move . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 59 4.5. copy . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 60 4.6. test . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 61 5. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 6 62 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 7 63 7. Security Considerations . . . . . . . . . . . . . . . . . . . 8 64 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 8 65 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 8 66 9.1. Normative References . . . . . . . . . . . . . . . . . . . 8 67 9.2. Informative References . . . . . . . . . . . . . . . . . . 8 68 Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 9 69 A.1. Adding an Object Member . . . . . . . . . . . . . . . . . 9 70 A.2. Adding an Array Element . . . . . . . . . . . . . . . . . 9 71 A.3. Removing an Object Member . . . . . . . . . . . . . . . . 9 72 A.4. Removing an Array Element . . . . . . . . . . . . . . . . 10 73 A.5. Replacing a Value . . . . . . . . . . . . . . . . . . . . 10 74 A.6. Moving a Value . . . . . . . . . . . . . . . . . . . . . . 11 75 A.7. Moving an Array Element . . . . . . . . . . . . . . . . . 11 76 A.8. Testing a Value: Success . . . . . . . . . . . . . . . . . 12 77 A.9. Testing a Value: Error . . . . . . . . . . . . . . . . . . 12 78 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 13 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. If values are or contain objects or arrays, they must be 251 identical (i.e. same order of elements, with the same values). 253 Example: 255 { "test": "/a/b/c", "value": "foo" } 257 It is an error condition if the value at the specified location is 258 not equal to the specified value. 260 5. Error Handling 262 If an error condition occurs, evaluation of the JSON Patch document 263 SHOULD terminate and application of the entire patch document SHALL 264 NOT be deemed successful. 266 6. IANA Considerations 268 The Internet media type for a JSON Patch document is application/ 269 json-patch. 271 Type name: application 273 Subtype name: json-patch 275 Required parameters: none 277 Optional parameters: none 279 Encoding considerations: binary 281 Security considerations: 282 See Security Considerations in section 7. 284 Interoperability considerations: N/A 286 Published specification: 287 [this memo] 289 Applications that use this media type: 290 Applications that manipulate JSON documents. 292 Additional information: 294 Magic number(s): N/A 296 File extension(s): .json-patch 298 Macintosh file type code(s): TEXT 300 Person & email address to contact for further information: 301 Paul C. Bryan 303 Intended usage: COMMON 305 Restrictions on usage: none 307 Author: Paul C. Bryan 309 Change controller: IETF 311 7. Security Considerations 313 This specification has the same security considerations as JSON 314 [RFC4627] and [JSON-Pointer]. 316 8. Acknowledgements 318 The following individuals contributed ideas, feedback and wording to 319 this specification: 321 Mike Acar, Mike Amundsen, Paul Davis, Murray S. Kucherawy, Dean 322 Landolt, Randall Leeds, Julian Reschke, Eli Stevens. 324 The structure of a JSON Patch document was influenced by the XML 325 Patch document [RFC5261] specification. 327 9. References 329 9.1. Normative References 331 [JSON-Pointer] 332 Bryan, P. and K. Zyp, "JSON Pointer", 333 draft-ietf-appsawg-json-pointer-01 (work in progress), 334 March 2012. 336 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 337 Requirement Levels", BCP 14, RFC 2119, March 1997. 339 [RFC4627] Crockford, D., "The application/json Media Type for 340 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 342 9.2. Informative References 344 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 345 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 346 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 348 [RFC5261] Urpalainen, J., "An Extensible Markup Language (XML) Patch 349 Operations Framework Utilizing XML Path Language (XPath) 350 Selectors", RFC 5261, September 2008. 352 [RFC5789] Dusseault, L. and J. Snell, "PATCH Method for HTTP", 353 RFC 5789, March 2010. 355 Appendix A. Examples 357 A.1. Adding an Object Member 359 An example target JSON document: 361 { 362 "foo": "bar" 363 } 365 A JSON Patch document: 367 [ 368 { "add": "/baz", "value": "qux" } 369 ] 371 The resulting JSON document: 373 { 374 "baz": "qux", 375 "foo": "bar" 376 } 378 A.2. Adding an Array Element 380 An example target JSON document: 382 { 383 "foo": [ "bar", "baz" ] 384 } 386 A JSON Patch document: 388 [ 389 { "add": "/foo/1", "value": "qux" } 390 ] 392 The resulting JSON document: 394 { 395 "foo": [ "bar", "qux", "baz" ] 396 } 398 A.3. Removing an Object Member 400 An example target JSON document: 402 { 403 "baz": "qux", 404 "foo": "bar" 405 } 407 A JSON Patch document: 409 [ 410 { "remove": "/baz" } 411 ] 413 The resulting JSON document: 415 { 416 "foo": "bar" 417 } 419 A.4. Removing an Array Element 421 An example target JSON document: 423 { 424 "foo": [ "bar", "qux", "baz" ] 425 } 427 A JSON Patch document: 429 [ 430 { "remove": "/foo/1" } 431 ] 433 The resulting JSON document: 435 { 436 "foo": [ "bar", "baz" ] 437 } 439 A.5. Replacing a Value 441 An example target JSON document: 443 { 444 "baz": "qux", 445 "foo": "bar" 446 } 448 A JSON Patch document: 450 [ 451 { "replace": "/baz", "value": "boo" } 452 ] 454 The resulting JSON document: 456 { 457 "baz": "boo", 458 "foo": "bar" 459 } 461 A.6. Moving a Value 463 An example target JSON document: 465 { 466 "foo": { 467 "bar": "baz", 468 "waldo": "fred" 469 } 470 "qux": { 471 "corge": "grault" 472 } 473 } 475 A JSON Patch document: 477 [ 478 { "move": "/foo/waldo", to: "/qux/thud" } 479 ] 481 The resulting JSON document: 483 { 484 "foo": { 485 "bar": "baz" 486 } 487 "qux": { 488 "corge": "grault", 489 "thud": "fred" 490 } 491 } 493 A.7. Moving an Array Element 495 An example target JSON document: 497 { 498 "foo": [ "all", "grass", "cows", "eat" ] 499 } 501 A JSON Patch document: 503 [ 504 { "move": "/foo/1", "to": "/foo/3" } 505 ] 507 The resulting JSON document: 509 { 510 "foo": [ "all", "cows", "eat", "grass" ] 511 } 513 A.8. Testing a Value: Success 515 An example target JSON document: 517 { 518 "baz": "qux", 519 "foo": [ "a", 2, "c" ] 520 } 522 A JSON Patch document that will result in successful evaluation: 524 [ 525 { "test": "/baz", "value": "qux" }, 526 { "test": "/foo/1", "value": 2 } 527 ] 529 A.9. Testing a Value: Error 531 An example target JSON document: 533 { 534 "baz": "qux" 535 } 537 A JSON Patch document that will result in an error condition: 539 [ 540 { "test": "/baz", "value": "bar" } 541 ] 543 Authors' Addresses 545 Paul C. Bryan (editor) 546 ForgeRock 548 Phone: +1 604 783 1481 549 Email: pbryan@anode.ca 551 Mark Nottingham (editor) 552 Rackspace 554 Email: mnot@mnot.net