#null #patch #merge #json #rfc #format #http

json-merge-patch

Implementation of RFC 7396 - JSON Merge Patch

1 unstable release

0.0.1 Mar 28, 2023

#46 in #null

Download history 324/week @ 2024-07-25 374/week @ 2024-08-01 405/week @ 2024-08-08 246/week @ 2024-08-15 357/week @ 2024-08-22 348/week @ 2024-08-29 494/week @ 2024-09-05 542/week @ 2024-09-12 472/week @ 2024-09-19 879/week @ 2024-09-26 1262/week @ 2024-10-03 755/week @ 2024-10-10 765/week @ 2024-10-17 1132/week @ 2024-10-24 895/week @ 2024-10-31 660/week @ 2024-11-07

3,700 downloads per month

MIT license

14KB
213 lines

JSON Merge Patch

Rust implementation of RFC 7396

This specification defines the JSON merge patch format and processing rules. The merge patch format is primarily intended for use with the HTTP PATCH method as a means of describing a set of modifications to a target resource's content.

For example, given the following original JSON document:

{
  "a": "b",
  "c": {
    "d": "e",
    "f": "g"
  }
}

Changing the value of "a" and removing "f" can be achieved by sending:

{
  "a":"z",
  "c": {
    "f": null
  }
}

When applied to the target resource, the value of the "a" member is replaced with "z" and "f" is removed, leaving the remaining content untouched.

Example Test Cases:

ORIGINAL PATCH RESULT
{"a":"b"} {"a":"c"} {"a":"c"}
{"a":"b"} {"b":"c"} {"a":"b", "b":"c"}
{"a":"b"} {"a":null} {}
{"a":"b","b":"c"} {"a":null} {"b":"c"}
{"a":["b"]} {"a":"c"} {"a":"c"}
{"a":"c"} {"a":["b"]} {"a":["b"]}
{"a":{"b":"c"}} {"a":{"b":"d","c":null}} {"a":{"b":"d"}}
{"a":[ {"b":"c"}]} {"a":[1]} {"a":[1]}
["a","b"] ["c","d"] ["c","d"]
{"a":"b"} ["c"] ["c"]
{"a":"b"} ["c"] ["c"]
{"a":"foo"} null null
{"a":"foo"} "bar" "bar"
{"e":null} {"a":1} {"e":null, "a":1}
[1,2] {"a":"b", "c":null} {"a":"b"}
{} {"a":{"bb":{"ccc":null}}} {"a":{"bb":{}}}

Dependencies

~0.5–1MB
~20K SLoC