diff --git a/Cargo.lock b/Cargo.lock index fa18fd1..56a1a6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -795,9 +795,9 @@ dependencies = [ [[package]] name = "jsonpath-rust" -version = "0.7.5" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c00ae348f9f8fd2d09f82a98ca381c60df9e0820d8d79fce43e649b4dc3128b" +checksum = "633a7320c4bb672863a3782e89b9094ad70285e097ff6832cddd0ec615beadfa" dependencies = [ "pest", "pest_derive", diff --git a/Cargo.toml b/Cargo.toml index 8051541..7e05f3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ serde_json = "1.0" uuid = { version = "1.8.0", features = ["v7", "serde"] } chrono = { version = "0.4.43", features = ["serde"] } jsonb = "0.5.5" -jsonpath-rust = "0.7" +jsonpath-rust = "1.0" tokio = { version = "1.49.0", features = ["full"] } async-trait = "0.1.89" futures = "0.3.31" diff --git a/src/query.rs b/src/query.rs index 7815996..a889a05 100644 --- a/src/query.rs +++ b/src/query.rs @@ -1,8 +1,7 @@ use crate::db::DB; -use jsonpath_rust::JsonPath; +use jsonpath_rust::query::js_path_vals; use serde_json::Value; use std::cmp::Ordering; -use std::str::FromStr; use tracing::{Level, span}; @@ -218,18 +217,13 @@ fn evaluate_expression(expr: &Expression, doc: &Value) -> Value { match expr { Expression::FieldReference(path) => get_path(doc, path).unwrap_or(Value::Null), Expression::JsonPath(path) => { - if let Ok(p) = JsonPath::from_str(path) { - let inst = p.find(doc); - if let Some(arr) = inst.as_array() { - if arr.is_empty() { - Value::Null - } else if arr.len() == 1 { - arr[0].clone() - } else { - inst.clone() - } + if let Ok(nodes) = js_path_vals(path, doc) { + if nodes.is_empty() { + Value::Null + } else if nodes.len() == 1 { + nodes[0].clone() } else { - inst + Value::Array(nodes.into_iter().cloned().collect()) } } else { Value::Null