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

json-merge-patch

实现RFC 7396 - JSON Merge Patch

1个不稳定版本

0.0.1 2023年3月28日

#47 in #null

Download history 274/week @ 2024-04-24 303/week @ 2024-05-01 265/week @ 2024-05-08 443/week @ 2024-05-15 172/week @ 2024-05-22 227/week @ 2024-05-29 229/week @ 2024-06-05 293/week @ 2024-06-12 376/week @ 2024-06-19 525/week @ 2024-06-26 167/week @ 2024-07-03 314/week @ 2024-07-10 490/week @ 2024-07-17 369/week @ 2024-07-24 380/week @ 2024-07-31 373/week @ 2024-08-07

1,664 每月下载量

MIT 许可证

14KB
213

JSON Merge Patch

Rust对RFC 7396的实现

本规范定义了JSON合并补丁格式和加工规则。合并补丁格式主要旨在与HTTP PATCH方法一起使用,作为描述对目标资源内容修改集的一种手段。

例如,给定以下原始JSON文档

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

通过发送以下内容可以更改"a"的值并删除"f":

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

当应用于目标资源时,"a"成员的值被替换为"z","f"被删除,其余内容保持不变。

示例测试用例

原始 PATCH 结果
{"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":{}}}

依赖

~0.5–1MB
~20K SLoC