A Rust implementation of JsonPath.
[?((@.id > 10 || @.id < -1) && @.msg contains 'jsonpath')]
```rust use jsonpath::JsonPathQuery; use serdejson::json;
let object = json!({"greetings": "hello, jsonpath"}); let result = object.query("$['greetings']"); asserteq!(Ok(json!("hello, json_path")), result); ```
shell
$ cargo install json_path_bin
$ echo '{"msg": "hello!"}' | json_path_bin -j '$.msg'
"hello!"
$
| Operator | Description |
| :------------------------ | :-------------------------------------------------------------- |
| $
| The root element to query. This starts all path expressions. |
| @
| The current node being processed by a filter predicate. |
| *
| Wildcard. Available anywhere a name or numeric are required. |
| ..
| Deep scan. Available anywhere a name is required. |
| .<name>
| Dot-notated child |
| ['<name>' (, '<name>')]
| Bracket-notated child or children |
| [<number> (, <number>)]
| Array index or indexes |
| [start:end]
| Array slice operator |
| [?(<expression>)]
| Filter expression. Expression must evaluate to a boolean value. |
[1:]
slice from index 1 (inclusive) to the end[:-1]
slice from begining to the last item (exclusive)[1:10]
slice from 1 (inclusive) to 10 (exclusive)| Operator | Description |
| :---------------- | :--------------------------------------------------------------------------------------------------------------- |
| ==
| left is equal to right (note that 1 is not equal to '1') |
| !=
| left is not equal to right |
| <
| left is less than right |
| <=
| left is less or equal to right |
| >
| left is greater than right |
| >=
| left is greater than or equal to right |
| =~
| WIP, left matches regular expression [?(@.name =~ /foo.*?/i)] |
| !
| Used to negate a filter: [?(!@.isbn)] matches items that do not have the isbn property. |
| in
| left exists in right [?(@.size in ['S', 'M'])] |
| nin
| left does not exists in right |
| subsetof
| left is a subset of right [?(@.sizes subsetof ['S', 'M', 'L'])] |
| contains
| Checks if a string contains the specified substring (case-sensitive), or an array contains the specified element |
| anyof
| left has an intersection with right [?(@.sizes anyof ['M', 'L'])] |
| noneof
| left has no intersection with right [?(@.sizes noneof ['M', 'L'])] |
| size
| size of left (array or string) should match right |
| empty
| left (array or string) should be empty, e.g.: [?(@.name empty false)] |
| (<expressions>)
| use parenthesis to group expressions, e.g. [?(!(@.sizes contains 'M'))] |