#merge-patch #json

json-patch

RFC 6902, JavaScript Object Notation (JSON) Patch

19 releases (9 stable)

4.2.0 Apr 30, 2026
4.1.0 Sep 16, 2025
4.0.0 Feb 24, 2025
3.1.0 Feb 24, 2025
0.2.1 Nov 3, 2017

#21 in Web programming

Download history 1063327/week @ 2026-01-23 1065305/week @ 2026-01-30 1104751/week @ 2026-02-06 1055218/week @ 2026-02-13 1248374/week @ 2026-02-20 1364001/week @ 2026-02-27 1531415/week @ 2026-03-06 1461011/week @ 2026-03-13 1167625/week @ 2026-03-20 1160681/week @ 2026-03-27 1184632/week @ 2026-04-03 1299092/week @ 2026-04-10 1223828/week @ 2026-04-17 1341883/week @ 2026-04-24 1365999/week @ 2026-05-01 1546163/week @ 2026-05-08

5,719,084 downloads per month
Used in 1,068 crates (118 directly)

MIT/Apache

39KB
675 lines

crates.io crates.io Build Codecov

json-patch

A JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7396) implementation for Rust.

Usage

Add this to your Cargo.toml:

[dependencies]
json-patch = "*"

Examples

Create and patch document using 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" }
]));

Create and patch document using 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"
}));

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.7–1.8MB
~37K SLoC