The json-toolkit
crate exposes all the common manipulation/validation operation expected from a JSON pointer and support
several JSON value representation :
- Encode RFC6901 representation in Pointer
type.
- Manipulate any JSON value by a JSON pointer.
```rust use jsontoolkit::{ValueExt, Pointer}; use serdejson::{Value, json};
let mut json = json!({ "foo": "bar", "zoo": { "id": 1 } });
json.insertat(&Pointer::new("/zoo/newfield").unwrap(), "newvalue").unwrap(); asserteq!(json, json!({ "foo": "bar", "zoo": { "id": 1, "newfield": "newvalue" } }));
let oldvalue = json.insert("foo".tostring(), 42).unwrap(); asserteq!(oldvalue, Some("bar".into())); asserteq!(json, json!({ "foo": 42, "zoo": { "id": 1, "newfield": "new_value" } }));
let id = ValueExt::pointer(&json, &Pointer::new("/zoo/id").unwrap()); assert_eq!(id, Some(&1.into())); ```
json-toolkit
supports several JSON value representation, and has features that may be enabled or disabled :
- serde
: Enable serde
{de}serialization on Pointer
type
and implement ValueExt
on serde_json::Value
type.
- json
: Implement ValueExt
on json::JsonValue
type.
Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)