jsonpath_rust::path

Trait JsonLike

Source
pub trait JsonLike:
    Default
    + Clone
    + Debug
    + for<'a> From<&'a str>
    + From<Vec<String>>
    + From<bool>
    + From<i64>
    + From<f64>
    + From<Vec<Self>>
    + From<String>
    + PartialEq
    + 'static {
Show 18 methods // Required methods fn get(&self, key: &str) -> Option<&Self>; fn itre(&self, pref: String) -> Vec<JsonPathValue<'_, Self>>; fn array_len(&self) -> JsonPathValue<'static, Self>; fn init_with_usize(cnt: usize) -> Self; fn deep_flatten(&self, pref: String) -> Vec<(&Self, String)>; fn deep_path_by_key<'a>( &'a self, key: ObjectField<'a, Self>, pref: String, ) -> Vec<(&'a Self, String)>; fn as_u64(&self) -> Option<u64>; fn is_array(&self) -> bool; fn as_array(&self) -> Option<&Vec<Self>>; fn size(left: Vec<&Self>, right: Vec<&Self>) -> bool; fn sub_set_of(left: Vec<&Self>, right: Vec<&Self>) -> bool; fn any_of(left: Vec<&Self>, right: Vec<&Self>) -> bool; fn regex(left: Vec<&Self>, right: Vec<&Self>) -> bool; fn inside(left: Vec<&Self>, right: Vec<&Self>) -> bool; fn less(left: Vec<&Self>, right: Vec<&Self>) -> bool; fn eq(left: Vec<&Self>, right: Vec<&Self>) -> bool; fn null() -> Self; fn array(data: Vec<Self>) -> Self;
}
Expand description

The JsonLike trait defines a set of methods and associated types for working with JSON-like data structures.

It provides a common interface for accessing and manipulating JSON data, allowing for operations such as

  • retrieving values by key,
  • iterating over elements
  • performing various comparisons and transformations.

The trait is implemented for the serde_json::Value type already

Required Methods§

Source

fn get(&self, key: &str) -> Option<&Self>

Retrieves a reference to the value associated with the given key.

Source

fn itre(&self, pref: String) -> Vec<JsonPathValue<'_, Self>>

Iterates over the elements with a given prefix and returns a vector of JsonPathValue.

Source

fn array_len(&self) -> JsonPathValue<'static, Self>

Returns the length of the array as a JsonPathValue.

Source

fn init_with_usize(cnt: usize) -> Self

Initializes an instance with a specific size.

Source

fn deep_flatten(&self, pref: String) -> Vec<(&Self, String)>

Flattens nested structures and returns a vector of tuples containing references to the elements and their paths.

Source

fn deep_path_by_key<'a>( &'a self, key: ObjectField<'a, Self>, pref: String, ) -> Vec<(&'a Self, String)>

Performs a deep search by key and returns a vector of tuples containing references to the elements and their paths.

Source

fn as_u64(&self) -> Option<u64>

Converts the element to an Option<u64>.

Source

fn is_array(&self) -> bool

Checks if the element is an array.

Source

fn as_array(&self) -> Option<&Vec<Self>>

Converts the element to an Option<&Vec<Self>>.

Source

fn size(left: Vec<&Self>, right: Vec<&Self>) -> bool

Compares the size of two vectors of references to elements.

Source

fn sub_set_of(left: Vec<&Self>, right: Vec<&Self>) -> bool

Checks if the left vector is a subset of the right vector.

Source

fn any_of(left: Vec<&Self>, right: Vec<&Self>) -> bool

Checks if any element in the left vector is present in the right vector.

Source

fn regex(left: Vec<&Self>, right: Vec<&Self>) -> bool

Checks if the elements in the left vector match the regex pattern in the right vector.

Source

fn inside(left: Vec<&Self>, right: Vec<&Self>) -> bool

Checks if any element in the left vector is inside the right vector.

Source

fn less(left: Vec<&Self>, right: Vec<&Self>) -> bool

Ensures the number on the left side is less than the number on the right side.

Source

fn eq(left: Vec<&Self>, right: Vec<&Self>) -> bool

Compares elements for equality.

Source

fn null() -> Self

Returns a null value.

Source

fn array(data: Vec<Self>) -> Self

Creates an array from a vector of elements.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl JsonLike for Value

Source§

fn less(left: Vec<&Self>, right: Vec<&Self>) -> bool

ensure the number on the left side is less the number on the right side

Source§

fn eq(left: Vec<&Self>, right: Vec<&Self>) -> bool

compare elements

Source§

fn is_array(&self) -> bool

Source§

fn array(data: Vec<Self>) -> Self

Source§

fn null() -> Self

Source§

fn get(&self, key: &str) -> Option<&Self>

Source§

fn itre(&self, pref: String) -> Vec<JsonPathValue<'_, Self>>

Source§

fn array_len(&self) -> JsonPathValue<'static, Self>

Source§

fn init_with_usize(cnt: usize) -> Self

Source§

fn deep_flatten(&self, pref: String) -> Vec<(&Self, String)>

Source§

fn deep_path_by_key<'a>( &'a self, key: ObjectField<'a, Self>, pref: String, ) -> Vec<(&'a Self, String)>

Source§

fn as_u64(&self) -> Option<u64>

Source§

fn as_array(&self) -> Option<&Vec<Self>>

Source§

fn size(left: Vec<&Self>, right: Vec<&Self>) -> bool

Source§

fn sub_set_of(left: Vec<&Self>, right: Vec<&Self>) -> bool

Source§

fn any_of(left: Vec<&Self>, right: Vec<&Self>) -> bool

Source§

fn regex(left: Vec<&Self>, right: Vec<&Self>) -> bool

Source§

fn inside(left: Vec<&Self>, right: Vec<&Self>) -> bool

Implementors§