json-pointer
A crate for parsing and using JSON pointers, as specified in RFC
6901. Unlike the pointer method
built into serde_json, this handles both validating JSON Pointers before
use and the URI Fragment Identifier Representation.
Creating a JSON Pointer
JSON pointers can be created with a literal [&str], or parsed from a String.
let from_strs = new;
let parsed = "/foo/bar"..unwrap;
assert_eq!;
}
Using a JSON Pointer
The JsonPointer type provides .get() and .get_mut(), to get references
and mutable references to the appropriate value, respectively.
let ptr = "/foo/bar"..unwrap;
let document = json!;
let indexed = ptr.get.unwrap;
assert_eq!;
URI Fragment Identifier Representation
JSON Pointers can be embedded in the fragment portion of a URI. This is the
reason why most JSON pointer libraries require a # character at the beginning
of a JSON pointer. The crate will detect the leading # as an indicator to
parse in URI Fragment Identifier Representation. Note that this means that this
crate does not support parsing full URIs.
let str_ptr = "/f%o"..unwrap;
let uri_ptr = "#/f%25o"..unwrap;
assert_eq!;