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
andjsonbb
. Custom JSON types are also supported.
Usage
use ;
use JsonPath;
let json = json!;
let path = new.unwrap;
let nodes = path.query.unwrap;
assert_eq!;
assert_eq!;
JSON Path Syntax
See PostgreSQL documentation for more details.
-
strict
andlax
mode -
$
: Root object -
@
: Current object -
[index]
: An array element by index-
[start to end]
: An array slice -
[index1, index2, ...]
: Multiple array elements -
[last]
: The last array element
-
-
.name
: An object member by name -
[*]
: Any array element -
.*
: Any object member -
.**
: Any descendant object member (Postgres extension) -
?(predicate)
: Filter expression-
==
,!=
/<>
,<
,<=
,>
,>=
: Comparison -
&&
,||
,!
: Logical operators -
is unknown
: Check if the value is unknown -
like_regex
: Check if the string matches the regular expression -
starts with
: Check if the string starts with the given prefix -
exists(expr)
: Check if the expression matches any value
-
- Operations
-
+
: Addition / Unary plus -
-
: Subtraction / Negation -
*
: Multiplication -
/
: Division -
%
: Modulo
-
- Methods
-
.type()
-
.size()
-
.double()
-
.ceiling()
-
.floor()
-
.abs()
-
.datetime()
-
.datetime(template)
-
.keyvalue()
-
Testing
This crate is tested against PostgreSQL regression tests: 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.