Struct jsonpath_plus::JsonPath
source · [−]pub struct JsonPath { /* private fields */ }
Expand description
A compiled JSON path. Can be used to match against items any number of times, preventing recompilation of the same pattern many times.
Implementations
sourceimpl JsonPath
impl JsonPath
sourcepub fn compile(pattern: &str) -> Result<JsonPath, ParseError>
pub fn compile(pattern: &str) -> Result<JsonPath, ParseError>
Compile a JSON path, which can be used to match items multiple times.
Errors
- If the provided pattern fails to parse as a valid JSON path
sourcepub fn find<'a>(&self, value: &'a Value) -> Vec<&'a Value>
pub fn find<'a>(&self, value: &'a Value) -> Vec<&'a Value>
Find this pattern in the provided JSON value
sourcepub fn find_paths(&self, value: &Value) -> Vec<IdxPath>
pub fn find_paths(&self, value: &Value) -> Vec<IdxPath>
Find this pattern in the provided JSON value, and return the shortest paths to all found values as a chain of indices
sourcepub fn delete(&self, value: &Value) -> Value
pub fn delete(&self, value: &Value) -> Value
Delete all items matched by this pattern on the provided JSON value, and return the resulting object
sourcepub fn delete_on(&self, value: &mut Value)
pub fn delete_on(&self, value: &mut Value)
Delete all items matched by this pattern on the provided JSON value, operating in-place
sourcepub fn replace(&self, value: &Value, f: impl FnMut(&Value) -> Value) -> Value
pub fn replace(&self, value: &Value, f: impl FnMut(&Value) -> Value) -> Value
Replace items matched by this pattern on the provided JSON value, filling them with the value returned by the provided function, then return the resulting object
sourcepub fn replace_on(&self, value: &mut Value, f: impl FnMut(&Value) -> Value)
pub fn replace_on(&self, value: &mut Value, f: impl FnMut(&Value) -> Value)
Replace items matched by this pattern on the provided JSON value, filling them the value returned by the provided function, operating in-place
sourcepub fn try_replace(
&self,
value: &Value,
f: impl FnMut(&Value) -> Option<Value>
) -> Value
pub fn try_replace(
&self,
value: &Value,
f: impl FnMut(&Value) -> Option<Value>
) -> Value
Replace or delete items matched by this pattern on the provided JSON value. Replaces if the
provided method returns Some
, deletes if the provided method returns None
. This method
then returns the resulting object
sourcepub fn try_replace_on(
&self,
value: &mut Value,
f: impl FnMut(&Value) -> Option<Value>
)
pub fn try_replace_on(
&self,
value: &mut Value,
f: impl FnMut(&Value) -> Option<Value>
)
Replace or delete items matched by this pattern on the provided JSON value. Replaces if the
provided method returns Some
, deletes if the provided method returns None
. This method
operates in-place on the provided value
sourcepub fn delete_str(&self, str: &str) -> Result<Value, Error>
pub fn delete_str(&self, str: &str) -> Result<Value, Error>
Delete items matching this pattern in the provided JSON string
Errors
- If the provided value fails to deserialize
Auto Trait Implementations
impl RefUnwindSafe for Path
impl Send for Path
impl Sync for Path
impl Unpin for Path
impl UnwindSafe for Path
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more