Crates.io | json-toolkit |
lib.rs | json-toolkit |
version | 0.1.1 |
source | src |
created_at | 2022-08-24 12:49:40.256282 |
updated_at | 2022-08-24 13:04:59.901524 |
description | An utility library providing pointer facilities and extending 3rd-parties JSON types |
homepage | https://github.com/alekece/json-toolkit-rs |
repository | https://github.com/alekece/json-toolkit-rs |
max_upload_size | |
id | 651635 |
size | 39,695 |
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()));
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)