4 releases
0.1.3 | May 2, 2021 |
---|---|
0.1.2 | Apr 29, 2021 |
0.1.1 | Jan 28, 2021 |
0.1.0 | Jan 18, 2021 |
#246 in #pointers
Used in 2 crates
(via sppparse)
4KB
62 lines
Sppparse (Sparsed Pointer Parser)
Introduction
Modern JSON
/YAML
tends to use JSON Pointer. This crate aims to facilitate their use.
Built on top of serde, this library allows a generic way to read and modify documents containing $ref
.
Features
The following features are available :
url
: Add support forurl::Url
semver
: Add support forsemver::Version
Example
#[derive(Debug, Deserialize, Serialize, Sparsable)]
struct ObjectExampleParsed {
hello: String,
obj: HashMap<String, SparseSelector<String>>,
}
fn main() {
let json_value = json!({
"hello": "world",
"obj": {
"key1": {
"$ref": "#/hello"
}
}
});
let parsed_obj: SparseRoot<ObjectExampleParsed> =
SparseRoot::new_from_value(json_value, PathBuf::from("hello.json"), vec![]).unwrap();
println!(
"{}",
parsed_obj
.root_get()
.unwrap()
.obj
.get("key1")
.unwrap()
.get()
.expect("the dereferenced pointer")
);
}
// Prints "world"
Dependencies
~2MB
~48K SLoC