Trait jsonpath_rust::JsonPathQuery

source ·
pub trait JsonPathQuery {
    // Required method
    fn path(self, query: &str) -> Result<Value, String>;
}
Expand description

the trait allows to mix the method path to the value of Value and thus the using can be shortened to the following one:

§Examples:

use std::str::FromStr;
use serde_json::{json,Value};
use jsonpath_rust::jp_v;
use crate::jsonpath_rust::{JsonPathFinder,JsonPathQuery,JsonPathInst,JsonPathValue};
fn test(){
        let json: Value = serde_json::from_str("{}").unwrap();
        let v = json.path("$..book[?(@.author size 10)].title").unwrap();
        assert_eq!(v, json!([]));

        let json: Value = serde_json::from_str("{}").unwrap();
        let path = json.path("$..book[?(@.author size 10)].title").unwrap();

        assert_eq!(path, json!(["Sayings of the Century"]));

        let json: Box<Value> = serde_json::from_str("{}").unwrap();
        let path: Box<JsonPathInst> = Box::from(JsonPathInst::from_str("$..book[?(@.author size 10)].title").unwrap());
        let  finder = JsonPathFinder::new(json, path);

        let v = finder.find_slice();
        let js = json!("Sayings of the Century");
        assert_eq!(v, jp_v![&js;"",]);
    }

#Note: the result is going to be cloned and therefore it can be significant for the huge queries

Required Methods§

source

fn path(self, query: &str) -> Result<Value, String>

Implementations on Foreign Types§

source§

impl JsonPathQuery for (Value, JsonPathConfig)

source§

fn path(self, query: &str) -> Result<Value, String>

source§

impl JsonPathQuery for (Box<Value>, JsonPathConfig)

source§

fn path(self, query: &str) -> Result<Value, String>

source§

impl JsonPathQuery for Value

source§

fn path(self, query: &str) -> Result<Value, String>

source§

impl JsonPathQuery for Box<Value>

source§

fn path(self, query: &str) -> Result<Value, String>

Implementors§