idnits 2.17.1 draft-pbryan-json-patch-04.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 (December 4, 2011) is 4527 days in the past. Is this intentional? Checking references for intended status: Informational ---------------------------------------------------------------------------- ** 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 Internet Engineering Task Force P. Bryan, Ed. 3 Internet-Draft ForgeRock US, Inc. 4 Intended status: Informational December 4, 2011 5 Expires: June 6, 2012 7 JSON Patch 8 draft-pbryan-json-patch-04 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 June 6, 2012. 33 Copyright Notice 35 Copyright (c) 2011 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 . . . . . . . . . . . . . . . . . . 8 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 HTTP [RFC2616] with a method to perform partial modifications 83 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 in the target 123 document to apply the operation. It is an error condition if an 124 operation object contains no operation member, or more than one 125 operation member. 127 4.1. add 129 The "add" operation adds a new value to the target document at the 130 specified location. The location must reference one of: the root of 131 the target document, a member to add to an existing object, or an 132 element to add to an existing array. The operation object contains a 133 "value" 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 in the target document at 151 the specified location. 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 in the target document at 166 the specified location 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 identical to expressing a "remove" operation for a 174 value, followed immediately by an "add" operation at the same 175 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 move the value to. This location must reference one of: the member 188 to add to an existing object, or an element to add to an existing 189 array. 191 Example: 193 { "move": "/a/b/c", to: "/a/b/d" } 195 This operation is identical to expressing a "remove" operation, 196 followed immediately by an "add" operation at the new location with 197 the value that was just removed. 199 If the location in the "to" member references a member of an existing 200 object in the target document, it is an error condition if a value at 201 the specified location already exists. 203 If the location in the "to" member references an element of an 204 existing array, any elements at or above the specified index are 205 shifted one position to the right. It is an error condition if the 206 specified index is greater than the number of elements in the array. 208 4.5. test 210 The "test" operation tests that a value in the target document at the 211 specified location is equal to a specified value. The operation 212 object contains a "value" member, which specifies the value to test 213 for. 215 Example: 217 { "test": "/a/b/c", value: "foo" } 219 It is an error condition if the value in the target document is not 220 equal to the specified value. 222 5. Error Handling 224 If an error condition occurs, evaluation of the JSON Patch document 225 SHOULD terminate and application of the entire patch document SHALL 226 NOT be deemed successful. 228 6. IANA Considerations 230 The Internet media type for a JSON Patch document is application/ 231 json-patch. 233 Type name: application 235 Subtype name: json-patch 237 Required parameters: none 239 Optional parameters: none 241 Encoding considerations: 242 Per JSON [RFC4627]: 8bit if UTF-8; binary if UTF-16 or UTF-32. 244 Security considerations: 245 See Security Considerations in section 7. 247 Interoperability considerations: N/A 249 Published specification: 250 draft-pbryan-json-patch-04 252 Applications that use this media type: 253 Applications that manipulate JSON documents. 255 Additional information: 257 Magic number(s): N/A 258 File extension(s): .json-patch 260 Macintosh file type code(s): TEXT 262 Person & email address to contact for further information: 263 Paul C. Bryan 265 Intended usage: COMMON 267 Restrictions on usage: none 269 Author: Paul C. Bryan 271 Change controller: Paul C. Bryan 273 7. Security Considerations 275 This specification has the same security considerations as JSON 276 [RFC4627] and JSON Pointer [JSON Pointer]. 278 8. Acknowledgements 280 The following individuals contributed ideas, feedback and wording, 281 which contributed to the content of this specification: 283 Mike Amundsen, Paul Davis, Dean Landolt, Randall Leeds, Mark 284 Nottingham, Julian Reschke, Eli Stevens. 286 The structure of a JSON Patch document was initially informed by the 287 XML Patch document [RFC5261] specification. 289 9. References 291 9.1. Normative References 293 [JSON Pointer] 294 Bryan, P. and K. Zyp, "JSON Pointer", October 2011, . 297 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 298 Requirement Levels", BCP 14, RFC 2119, March 1997. 300 [RFC4627] Crockford, D., "The application/json Media Type for 301 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 303 9.2. Informative References 305 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 306 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 307 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 309 [RFC5261] Urpalainen, J., "An Extensible Markup Language (XML) Patch 310 Operations Framework Utilizing XML Path Language (XPath) 311 Selectors", RFC 5261, September 2008. 313 [RFC5789] Dusseault, L. and J. Snell, "PATCH Method for HTTP", 314 RFC 5789, March 2010. 316 Appendix A. Examples 318 A.1. Adding an Object Member 320 An example target JSON document: 322 { 323 "foo": "bar" 324 } 326 A JSON Patch document: 328 [ 329 { "add": "/baz", "value": "qux" } 330 ] 332 The resulting JSON document: 334 { 335 "baz": "qux", 336 "foo": "bar" 337 } 339 A.2. Adding an Array Element 341 An example target JSON document: 343 { 344 "foo": [ "bar", "baz" ] 345 } 347 A JSON Patch document: 349 [ 350 { "add": "/foo/1", "value": "qux" } 351 ] 353 The resulting JSON document: 355 { 356 "foo": [ "bar", "qux", "baz" ] 357 } 359 A.3. Removing an Object Member 361 An example target JSON document: 363 { 364 "baz": "qux", 365 "foo": "bar" 366 } 368 A JSON Patch document: 370 [ 371 { "remove": "/baz" } 372 ] 374 The resulting JSON document: 376 { 377 "foo": "bar" 378 } 380 A.4. Removing an Array Element 382 An example target JSON document: 384 { 385 "foo": [ "bar", "qux", "baz" ] 386 } 388 A JSON Patch document: 390 [ 391 { "remove": "/foo/1" } 392 ] 394 The resulting JSON document: 396 { 397 "foo": ["bar", "baz"] 398 } 400 A.5. Replacing a Value 402 An example target JSON document: 404 { 405 "baz": "qux", 406 "foo": "bar" 407 } 409 A JSON Patch document: 411 [ 412 { "replace": "/baz", "value": "boo" } 413 ] 415 The resulting JSON document: 417 { 418 "baz": "boo", 419 "foo": "bar" 420 } 422 A.6. Moving a Value 424 An example target JSON document: 426 { 427 "foo": { 428 "bar": "baz", 429 "waldo": "fred" 430 } 431 "qux": { 432 "corge": "grault" 433 } 434 } 436 A JSON Patch document: 438 [ 439 { "move": "/foo/waldo", to: "/qux/thud" } 440 ] 442 The resulting JSON document: 444 { 445 "foo": { 446 "bar": "baz" 447 } 448 "qux": { 449 "corge": "grault", 450 "thud": "fred" 451 } 452 } 454 A.7. Moving an Array Element 456 An example target JSON document: 458 { 459 "foo": [ "all", "grass", "cows", "eat" ] 460 } 462 A JSON Patch document: 464 [ 465 { "move": "/foo/1", "to": "/foo/3" } 466 ] 468 The resulting JSON document: 470 { 471 "foo": [ "all", "cows", "eat", "grass" ] 472 } 474 A.8. Testing a Value: Success 476 An example target JSON document: 478 { 479 "baz": "qux", 480 "foo": [ "a", 2, "c" ] 481 } 483 A JSON Patch document, which will result in successful evaluation: 485 [ 486 { "test": "/baz", "value": "qux" }, 487 { "test": "/foo/1", "value": 2 } 488 ] 490 A.9. Testing a Value: Error 492 An example target JSON document: 494 { 495 "baz": "qux", 496 } 498 A JSON Patch document, which will result in an error condition: 500 [ 501 { "test": "/baz", "value": "bar" } 502 ] 504 Author's Address 506 Paul C. Bryan (editor) 507 ForgeRock US, Inc. 508 201 NE Park Plaza Drive Suite 196 509 Vancouver, WA 98684 510 USA 512 Phone: +1 604 783 1481 513 Email: paul.bryan@forgerock.com