2 releases
0.1.1 | Aug 24, 2022 |
---|---|
0.1.0 | Aug 24, 2022 |
#1189 in Encoding
33KB
562 lines
json-toolkit
The json-toolkit
crate exposes all the common manipulation/validation operation expected from a JSON pointer and support
several JSON value representation :
use json_toolkit::{ValueExt, Pointer};
use serde_json::{Value, json};
let mut json = json!({ "foo": "bar", "zoo": { "id": 1 } });
json.insert_at(&Pointer::new("/zoo/new_field").unwrap(), "new_value").unwrap();
assert_eq!(json, json!({ "foo": "bar", "zoo": { "id": 1, "new_field": "new_value" } }));
let old_value = json.insert("foo".to_string(), 42).unwrap();
assert_eq!(old_value, Some("bar".into()));
assert_eq!(json, json!({ "foo": 42, "zoo": { "id": 1, "new_field": "new_value" } }));
let id = ValueExt::pointer(&json, &Pointer::new("/zoo/id").unwrap());
assert_eq!(id, Some(&1.into()));
Features
json-toolkit
supports several JSON value representation, and has features that may be enabled or disabled :
serde
: Enableserde
{de}serialization onPointer
type and implementValueExt
onserde_json::Value
type.json
: ImplementValueExt
onjson::JsonValue
type.
License
Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)
Dependencies
~0.4–1MB
~23K SLoC