Crates.io | json-predicate |
lib.rs | json-predicate |
version | 0.1.16 |
source | src |
created_at | 2023-12-26 17:20:02.476335 |
updated_at | 2024-03-29 16:50:59.640818 |
description | JSON Predicate lib based on draft-snell-json-07 |
homepage | |
repository | https://github.com/Miaxos/json-predicate |
max_upload_size | |
id | 1081068 |
size | 230,673 |
Partial implementation of Snell Json Predicate Draft 07.
Even if this Draft is Expired, it's still a pretty good draft of predicate over JSON.
This specification defines JSON Predicates, a JSON-based RFC4627 syntax for the description and serialization of logical boolean predicate operations intended to be used in conjunction with other JSON-based mechanisms, such as JSON Patch RFC6902, as a means of incorporating conditional processing.
JSON Predicates can be used, for instance, to extend a JSON Patch RFC6902 document to provide for a broader range of conditional processing options not currently supported by JSON Patch.
Given this JSON:
{
"a": {
"b": {
"c": "ABC!XYZ"
}
}
}
We could have a predicate like this:
{
"op": "and",
"path": "/a/b/c",
"apply": [
{
"op": "type",
"value": "string"
},
{
"op": "contains",
"value": "ABC"
}
]
}
which would evaluate as true
if evaluated against the previous JSON.
let predicate = Predicate::deserialize(serde_json::json!({
"op": "and",
"path": "/objA",
"apply": [
{
"op": "defined",
"path": "/stringX"
},
{
"op": "defined",
"path": "/stringXYZ"
}
],
}))?;
let evaluted_predicate: bool = predicate
.test(&ENTRY, PredicateContext::default());
The JSON Patch methods described in draft-snell-json-test-07 are not implemented yet.
Licensed under either of