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.

Object Safety§

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§