https://github.com/risingwavelabs/sql-json-path
SQL/JSON path engine in Rust.
https://github.com/risingwavelabs/sql-json-path
Last synced: 6 months ago
JSON representation
SQL/JSON path engine in Rust.
- Host: GitHub
- URL: https://github.com/risingwavelabs/sql-json-path
- Owner: risingwavelabs
- License: apache-2.0
- Created: 2023-11-17T10:35:14.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-05T09:50:00.000Z (almost 2 years ago)
- Last Synced: 2025-04-09T10:40:46.129Z (6 months ago)
- Language: Rust
- Homepage: https://risingwavelabs.github.io/sql-json-path/
- Size: 148 KB
- Stars: 7
- Watchers: 10
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# sql-json-path
[](https://github.com/risingwavelabs/sql-json-path/actions/workflows/ci.yml)
[](https://crates.io/crates/sql-json-path)
[](https://docs.rs/sql-json-path)[SQL/JSON Path] implementation in Rust.
## Features
- Compatible with [SQL/JSON Path] standard and PostgreSQL implementation.
- Independent from JSON implementation. It supports popular libraries like [`serde_json`], [`simd-json`] and [`jsonbb`]. Custom JSON types are also supported.[SQL/JSON Path]: https://github.com/obartunov/sqljsondoc/blob/master/jsonpath.md
[`serde_json`]: https://crates.io/crates/serde_json
[`simd-json`]: https://crates.io/crates/simd-json
[`jsonbb`]: https://crates.io/crates/jsonbb## Usage
```rust
use serde_json::{json, Value};
use sql_json_path::JsonPath;let json = json!({"a": 1});
let path = JsonPath::new("$.a").unwrap();let nodes = path.query(&json).unwrap();
assert_eq!(nodes.len(), 1);
assert_eq!(nodes[0].to_string(), "1");
```## JSON Path Syntax
See [PostgreSQL documentation](https://www.postgresql.org/docs/16/functions-json.html#FUNCTIONS-SQLJSON-PATH) for more details.
- [x] `strict` and `lax` mode
- [x] `$`: Root object
- [x] `@`: Current object
- [x] `[index]`: An array element by index
- [x] `[start to end]`: An array slice
- [x] `[index1, index2, ...]`: Multiple array elements
- [x] `[last]`: The last array element
- [x] `.name`: An object member by name
- [x] `[*]`: Any array element
- [x] `.*`: Any object member
- [x] `.**`: Any descendant object member (Postgres extension)
- [x] `?(predicate)`: Filter expression
- [x] `==`, `!=` / `<>`, `<`, `<=`, `>`, `>=`: Comparison
- [x] `&&`, `||`, `!`: Logical operators
- [x] `is unknown`: Check if the value is unknown
- [x] `like_regex`: Check if the string matches the regular expression
- [x] `starts with`: Check if the string starts with the given prefix
- [x] `exists(expr)`: Check if the expression matches any value
- [x] Operations
- [x] `+`: Addition / Unary plus
- [x] `-`: Subtraction / Negation
- [x] `*`: Multiplication
- [x] `/`: Division
- [x] `%`: Modulo
- [x] Methods
- [x] `.type()`
- [x] `.size()`
- [x] `.double()`
- [x] `.ceiling()`
- [x] `.floor()`
- [x] `.abs()`
- [ ] `.datetime()`
- [ ] `.datetime(template)`
- [x] `.keyvalue()`## Testing
This crate is tested against [PostgreSQL regression tests](tests/jsonb_jsonpath.out): `cargo test --test pg_jsonb_jsonpath`. 325 out of 430 tests are passed. 96 tests are skipped because they have unsupported features. 9 tests are failed because of incorrect implementation.
## License
Licensed under [Apache License, Version 2.0](LICENSE).