[−][src]Trait json_dotpath::DotPaths
Access and mutate nested JSON elements by dotted paths
The path is composed of keys separated by dots, e.g. foo.bar.1
.
Arrays are indexed by numeric strings or special keys (see dot_get()
and dot_set()
).
This trait is implemented for serde_json::Value
, specifically the
Map
, Array
, and Null
variants. Empty path can also be used to access a scalar.
Required methods
fn dot_get<T>(&self, path: &str) -> Option<T> where
T: DeserializeOwned,
T: DeserializeOwned,
Get an item by path, if present.
JSON null
becomes None
, same as unpopulated path.
Special keys
Arrays can be indexed by special keys for reading:
>
... last element
Panics
- If the path attempts to index into a scalar (e.g.
"foo.bar"
in{"foo": 123}
) - If the path uses invalid key in an array or map
fn dot_get_mut(&mut self, path: &str) -> Option<&mut Value>
fn dot_set<T>(&mut self, path: &str, value: T) where
T: Serialize,
T: Serialize,
Insert an item by path.
Special keys
Arrays can be indexed by special keys:
+
or>
... append-
or<
... prepend>n
... insert after an indexn
<n
... insert before an indexn
Panics
see dot_get()
fn dot_replace<T, U>(&mut self, path: &str, value: T) -> Option<U> where
T: Serialize,
U: DeserializeOwned,
T: Serialize,
U: DeserializeOwned,
Replace a value by path with a new value. The value types do not have to match.
Panics
see dot_get()
fn dot_take<T>(&mut self, path: &str) -> Option<T> where
T: DeserializeOwned,
T: DeserializeOwned,
Get an item using a path, removing it from the store. If no item was stored under this path, then None is returned.
Panics
see dot_get()
Provided methods
fn dot_get_or<T>(&self, path: &str, def: T) -> T where
T: DeserializeOwned,
T: DeserializeOwned,
fn dot_get_or_default<T>(&self, path: &str) -> T where
T: DeserializeOwned + Default,
T: DeserializeOwned + Default,
Get an item, or a default value using the Default trait
Special keys
see dot_get()
Panics
see dot_get()
fn dot_remove(&mut self, path: &str) -> bool
Implementations on Foreign Types
impl DotPaths for Value
[src]
fn dot_get<T>(&self, path: &str) -> Option<T> where
T: DeserializeOwned,
[src]
T: DeserializeOwned,
fn dot_get_mut(&mut self, path: &str) -> Option<&mut Value>
[src]
fn dot_set<T>(&mut self, path: &str, value: T) where
T: Serialize,
[src]
T: Serialize,
fn dot_replace<T, U>(&mut self, path: &str, value: T) -> Option<U> where
T: Serialize,
U: DeserializeOwned,
[src]
T: Serialize,
U: DeserializeOwned,
fn dot_take<T>(&mut self, path: &str) -> Option<T> where
T: DeserializeOwned,
[src]
T: DeserializeOwned,
impl DotPaths for Map<String, Value>
[src]
fn dot_get<T>(&self, path: &str) -> Option<T> where
T: DeserializeOwned,
[src]
T: DeserializeOwned,
fn dot_get_mut(&mut self, path: &str) -> Option<&mut Value>
[src]
fn dot_set<T>(&mut self, path: &str, value: T) where
T: Serialize,
[src]
T: Serialize,
fn dot_replace<T, U>(&mut self, path: &str, value: T) -> Option<U> where
T: Serialize,
U: DeserializeOwned,
[src]
T: Serialize,
U: DeserializeOwned,
fn dot_take<T>(&mut self, path: &str) -> Option<T> where
T: DeserializeOwned,
[src]
T: DeserializeOwned,
impl DotPaths for Vec<Value>
[src]
fn dot_get<T>(&self, path: &str) -> Option<T> where
T: DeserializeOwned,
[src]
T: DeserializeOwned,
fn dot_get_mut(&mut self, path: &str) -> Option<&mut Value>
[src]
fn dot_set<T>(&mut self, path: &str, value: T) where
T: Serialize,
[src]
T: Serialize,
fn dot_replace<T, U>(&mut self, path: &str, value: T) -> Option<U> where
T: Serialize,
U: DeserializeOwned,
[src]
T: Serialize,
U: DeserializeOwned,
fn dot_take<T>(&mut self, path: &str) -> Option<T> where
T: DeserializeOwned,
[src]
T: DeserializeOwned,