• Stars
    star
    125
  • Rank 280,418 (Top 6 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RFC 6902 (JSON Patch) / RFC 7396 (JSON Merge Patch) implementation for Rust

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.

More Repositories

1

siperl

RFC 3261 (SIP) implementation in Erlang
Erlang
22
star
2

lcd

HD4780 library for embedded Rust development (no-std)
Rust
16
star
3

dynser

Trait object-based deserialization in Rust
Rust
11
star
4

experiments

Rust
10
star
5

stepgen

Rust
9
star
6

traitor

πŸ¦€πŸ€ͺ✨ => πŸ’₯
Rust
7
star
7

eeprom

Higher-level API for FLASH on STM32 + EEPROM emulation on top of FLASH pages
Rust
6
star
8

mb-reloaded

Rust
6
star
9

jconts

Continuations support for Java
Java
6
star
10

dfp-rs

Rust
4
star
11

lcd-example-bluepill

Rust
3
star
12

patchy-sync

JavaScript
3
star
13

x2-feed

Rust
3
star
14

crazy-traits

Rust
3
star
15

stm32-hal

Extra APIs for STM32 peripherals (bit-band access, generalized GPIO)
Rust
3
star
16

erlang-cover-plugin

Jenkins plugin to generate code coverage reports for Erlang.
Java
2
star
17

Eclipse-Native2ASCII

Workaround for #65571 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=65571)
Java
2
star
18

idubrov.github.io

SCSS
1
star
19

rustdoc-crash

Rust
1
star
20

explainToMe

Chrome extension to automatically expand acronyms used on certain subreddits (SpaceX, Space, etc) using http://www.decronym.xyz/ API
JavaScript
1
star
21

garage-firmware

Eagle
1
star
22

nanorm

nanorm is a simple and lightweight data mapper framework for Java
Java
1
star
23

Lama-Brushless-Mixer

AVR-based mixer for brushless Lama V4 conversion
C
1
star
24

aoc2020

Rust
1
star
25

proc-macro-madness

Rust
1
star
26

SuperFeed

1-axis CNC controller with advanced capabilities
C
1
star
27

aoc2022

Rust
1
star
28

PowerFeed

Firmware for Arduino-based power feed for X2 mini-mill
C++
1
star
29

ivans-rv

TypeScript
1
star
30

advent-of-code

Rust
1
star
31

bluepill-tests

GDB
1
star
32

tuple-keys

Rust
1
star