dot-prop
Get, set, check, and delete nested JSON values by dot path.
get_property(&value, "foo.bar.0"), set_property(&mut value, "a[1].b", json!(2)). A
faithful Rust port of the widely-used
dot-prop npm package, operating on
[serde_json::Value].
Unlike json-pointer (RFC 6901, /-separated),
this uses the JavaScript dot-prop dot-path syntax: . separates keys, [i] indexes
arrays, and \ escapes a literal ., [, or \.
get_property,set_property,has_property,delete_propertyparse_path/stringify_path/escape_path, plusdeep_keysandunflatten- Prototype-pollution guard (
__proto__,prototype,constructorare rejected) - Differential-tested against the reference
dot-propimplementation (60k cases across all operations)
Install
[]
= "0.1"
= "1"
Usage
use json;
use ;
let mut value = json!;
assert_eq!;
assert_eq!;
assert!;
set_property;
assert_eq!;
delete_property; // leaves a null hole, like JS `delete`
assert_eq!;
// Flatten/expand helpers:
assert_eq!;
assert_eq!;
Notes
get_propertyreturns the value itself when the input is not an object/array (matching the reference's default-value behavior).- This crate sets the correct keys and values; the serialization order of object keys is
governed by
serde_json(enable itspreserve_orderfeature for insertion order). The JavaScript original reorders integer-like keys first — a runtime quirk that does not apply to Rust.
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
License
Licensed under either of MIT or Apache-2.0 at your option.