sql_json_path/
lib.rs

1// Copyright 2023 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! [SQL/JSON Path] implementation in Rust.
16//!
17//! # Features
18//!
19//! - Compatible with [SQL/JSON Path] standard and PostgreSQL implementation.
20//! - Independent from JSON implementation. It supports popular libraries like [`serde-json`],
21//!   [`simd-json`] and [`jsonbb`]. [Custom] JSON types are also supported.
22//!
23//! # Usage
24//!
25//! ```rust
26//! use serde_json::{json, Value};
27//! use sql_json_path::JsonPath;
28//!
29//! let json = json!({"a": 1});
30//! let path = JsonPath::new("$.a").unwrap();
31//!
32//! let nodes = path.query(&json).unwrap();
33//! assert_eq!(nodes.len(), 1);
34//! assert_eq!(nodes[0].to_string(), "1");
35//! ```
36//!
37//! [SQL/JSON Path]: https://github.com/obartunov/sqljsondoc/blob/master/jsonpath.md
38//! [`serde-json`]: https://crates.io/crates/serde_json
39//! [`simd-json`]: https://crates.io/crates/simd-json
40//! [`jsonbb`]: https://crates.io/crates/jsonbb
41//! [Custom]: crate::json
42
43mod ast;
44mod eval;
45pub mod json;
46mod parser;
47
48pub use ast::JsonPath;
49pub use eval::Error as EvalError;
50pub use parser::Error as ParseError;