besok / jsonpath-rust

Support for json-path in Rust

Home Page:https://crates.io/crates/jsonpath-rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Jsonpath with bool values or null panics

yuriy-mochurad opened this issue · comments

I am not able to use jsonpath that has bool or null values, even though it is mentioned in README. For example this code based on example:

use serde_json::{json,Value};
use jsonpath_rust::json_path_value;
use jsonpath_rust::JsonPathFinder;
use jsonpath_rust::JsonPathValue;

fn main(){
    let  finder = JsonPathFinder::from_str(r#"{"first":{"second":[{"active":1},{"passive":1}]}}"#, "$.first.second[?(@.active == true)]").unwrap();
    let slice_of_data:Vec<JsonPathValue<Value>> = finder.find_slice();
    let js = json!({"active":1});
    assert_eq!(slice_of_data, json_path_value![&js,]);
}

It is based on the example. Notice the jsonpath string is: $.first.second[?(@.active == true)]
The error when running is:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: " --> 1:30\n  |\n1 | $.first.second[?(@.active == true)]\n  |                              ^---\n  |\n  = expected atom"', src/main.rs:7:139

Looks like this case is not added to grammar rules

Potential fix: #23

That is true. I don't see any traces of true|false|null literals in gramma.

closed by #23