Expand description
§Assign values based on JSON Pointers
This module provides the Assign trait which allows for the assignment of
values based on a JSON Pointer.
This module is enabled by default with the "assign" feature flag.
§Expansion
The path will automatically be expanded if the Pointer is not fully
exhausted before reaching a non-existent key in the case of objects, index
in the case of arrays, or a scalar value (including null) based upon a
best-guess effort on the meaning of each Token:
- If the
Tokenis equal to"0"or"-", the token will be considered an index of an array. - All tokens not equal to
"0"or"-"will be considered keys of an object.
§Usage
Assign can be used directly or through the assign
method of Pointer.
use jsonptr::Pointer;
use serde_json::json;
let mut data = json!({"foo": "bar"});
let ptr = Pointer::from_static("/foo");
let replaced = ptr.assign(&mut data, "baz").unwrap();
assert_eq!(replaced, Some(json!("bar")));
assert_eq!(data, json!({"foo": "baz"}));§Provided implementations
| Lang | value type | feature flag | Default |
|---|---|---|---|
| JSON | serde_json::Value | "json" | ✓ |
| TOML | toml::Value | "toml" |
Enums§
- Error
- Possible error returned from
Assignimplementations forserde_json::Valueandtoml::Value.
Traits§
- Assign
- Implemented by types which can internally assign a
(
Value) at a path represented by a JSONPointer.
Type Aliases§
- Assign
Error Deprecated - Alias for
Error- indicates a value assignment failed.