Struct 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§

Source§

impl Path

Source

pub fn segments(&self) -> &[Segment]

A slice of the segments this path contains

Source§

impl JsonPath

Source

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
Source

pub fn find<'a>(&self, value: &'a Value) -> Vec<&'a Value>

Find this pattern in the provided JSON value

Source

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

Source

pub fn delete(&self, value: &Value) -> Value

Delete all items matched by this pattern on the provided JSON value, and return the resulting object

Source

pub fn delete_on(&self, value: &mut Value)

Delete all items matched by this pattern on the provided JSON value, operating in-place

Source

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

Source

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

Source

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

Source

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

Source

pub fn find_str(&self, str: &str) -> Result<Vec<Value>, Error>

Find this pattern in the provided JSON string

§Errors
  • If the provided value fails to deserialize
Source

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
Source

pub fn replace_str( &self, str: &str, f: impl FnMut(&Value) -> Value, ) -> Result<Value, Error>

Replace items matching this pattern in the provided JSON string

§Errors
  • If the provided value fails to deserialize
Source

pub fn try_replace_str( &self, str: &str, f: impl FnMut(&Value) -> Option<Value>, ) -> Result<Value, Error>

Replace or delete items matching this pattern in the provided JSON string

§Errors
  • If the provided value fails to deserialize

Trait Implementations§

Source§

impl Spanned for Path

Available on crate feature spanned only.
Source§

fn span(&self) -> Span

Get the source span of this item

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Chain<T> for T

Source§

fn len(&self) -> usize

The number of items that this chain link consists of.
Source§

fn append_to(self, v: &mut Vec<T>)

Append the elements in this link to the chain.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.