15 个版本 (5 个稳定)

2.0.0 2024年5月6日
1.4.0 2024年5月6日
1.2.0 2023年10月9日
1.0.0 2023年3月31日
0.2.1 2017年11月3日

#50 in 编码

Download history · Rust 包仓库 167688/week @ 2024-05-02 · Rust 包仓库 178879/week @ 2024-05-09 · Rust 包仓库 185893/week @ 2024-05-16 · Rust 包仓库 170418/week @ 2024-05-23 · Rust 包仓库 172857/week @ 2024-05-30 · Rust 包仓库 175170/week @ 2024-06-06 · Rust 包仓库 178568/week @ 2024-06-13 · Rust 包仓库 179936/week @ 2024-06-20 · Rust 包仓库 189374/week @ 2024-06-27 · Rust 包仓库 163660/week @ 2024-07-04 · Rust 包仓库 178740/week @ 2024-07-11 · Rust 包仓库 174251/week @ 2024-07-18 · Rust 包仓库 173010/week @ 2024-07-25 · Rust 包仓库 189091/week @ 2024-08-01 · Rust 包仓库 269190/week @ 2024-08-08 · Rust 包仓库 279750/week @ 2024-08-15 · Rust 包仓库

948,597 每月下载量
用于 311 个crate (49 个直接使用)

MIT/Apache

39KB
685

crates.io crates.io Build Codecov

json-patch

Rust 的 JSON Patch (RFC 6902)JSON Merge Patch (RFC 7396) 实现。

使用方法

将以下内容添加到您的 Cargo.toml

[dependencies]
json-patch = "*"

示例

使用 JSON Patch 创建和修补文档

#[macro_use]
use json_patch::{Patch, patch};
use serde_json::{from_value, json};

let mut doc = json!([
    { "name": "Andrew" },
    { "name": "Maxim" }
]);

let p: Patch = from_value(json!([
  { "op": "test", "path": "/0/name", "value": "Andrew" },
  { "op": "add", "path": "/0/happy", "value": true }
])).unwrap();

patch(&mut doc, &p).unwrap();
assert_eq!(doc, json!([
  { "name": "Andrew", "happy": true },
  { "name": "Maxim" }
]));

使用 JSON Merge Patch 创建和修补文档

#[macro_use]
use json_patch::merge;
use serde_json::json;

let mut doc = json!({
  "title": "Goodbye!",
  "author" : {
    "givenName" : "John",
    "familyName" : "Doe"
  },
  "tags":[ "example", "sample" ],
  "content": "This will be unchanged"
});

let patch = json!({
  "title": "Hello!",
  "phoneNumber": "+01-123-456-7890",
  "author": {
    "familyName": null
  },
  "tags": [ "example" ]
});

merge(&mut doc, &patch);
assert_eq!(doc, json!({
  "title": "Hello!",
  "author" : {
    "givenName" : "John"
  },
  "tags": [ "example" ],
  "content": "This will be unchanged",
  "phoneNumber": "+01-123-456-7890"
}));

许可协议

根据您的选择,许可协议为

贡献

除非您明确声明,否则您提交给作品中的任何贡献,如 Apache-2.0 许可证中定义,应如上所述双重许可,不附加任何额外的条款或条件。

依赖项

~1–2MB
~42K SLoC