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§
Source§impl 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
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Path
impl RefUnwindSafe for Path
impl Send for Path
impl Sync for Path
impl Unpin for Path
impl UnwindSafe for Path
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more