Skip to main content

ValueExt

Trait ValueExt 

Source
pub trait ValueExt {
    // Required methods
    fn jmespath_type(&self) -> JmespathType;
    fn is_truthy(&self) -> bool;
    fn get_field(&self, name: &str) -> Value;
    fn get_index(&self, idx: usize) -> Value;
    fn get_negative_index(&self, idx: usize) -> Value;
    fn slice(
        &self,
        start: Option<i32>,
        stop: Option<i32>,
        step: i32,
    ) -> Option<Vec<Value>>;
    fn compare(&self, comparator: &Comparator, other: &Value) -> Option<bool>;
    fn is_expref(&self) -> bool;
}
Expand description

Extension trait providing JMESPath operations on serde_json::Value.

Required Methods§

Source

fn jmespath_type(&self) -> JmespathType

Returns the JMESPath type name.

Source

fn is_truthy(&self) -> bool

Returns true if the value is “truthy” per the JMESPath spec.

  • null is falsy
  • false is falsy
  • "" (empty string) is falsy
  • [] (empty array) is falsy
  • {} (empty object) is falsy
  • Everything else is truthy
Source

fn get_field(&self, name: &str) -> Value

Extracts a named field from an object; returns Value::Null if not found.

Source

fn get_index(&self, idx: usize) -> Value

Extracts an element by positive index; returns Value::Null if out of range.

Source

fn get_negative_index(&self, idx: usize) -> Value

Extracts an element by negative index (counting from end).

Source

fn slice( &self, start: Option<i32>, stop: Option<i32>, step: i32, ) -> Option<Vec<Value>>

Slices an array with start/stop/step, per the JMESPath spec. Returns None if the value is not an array.

Source

fn compare(&self, comparator: &Comparator, other: &Value) -> Option<bool>

Compares two values using a JMESPath comparator. Returns None if the comparison is not valid for these types.

Source

fn is_expref(&self) -> bool

Returns true if this is an expref sentinel.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ValueExt for Value

Source§

fn jmespath_type(&self) -> JmespathType

Source§

fn is_truthy(&self) -> bool

Source§

fn get_field(&self, name: &str) -> Value

Source§

fn get_index(&self, idx: usize) -> Value

Source§

fn get_negative_index(&self, idx: usize) -> Value

Source§

fn slice( &self, start: Option<i32>, stop: Option<i32>, step: i32, ) -> Option<Vec<Value>>

Source§

fn compare(&self, comparator: &Comparator, other: &Value) -> Option<bool>

Source§

fn is_expref(&self) -> bool

Implementors§