| Crates.io | juspay_jsonlogic |
| lib.rs | juspay_jsonlogic |
| version | 0.5.5 |
| created_at | 2025-07-30 14:54:04.542676+00 |
| updated_at | 2025-07-30 14:54:04.542676+00 |
| description | A JsonLogic implementation in Rust |
| homepage | |
| repository | https://github.com/marvindv/jsonlogic_rs |
| max_upload_size | |
| id | 1773628 |
| size | 231,821 |
A JsonLogic implementation in Rust.
To use this library, add
[dependencies]
jsonlogic = "0.5"
to your Cargo.toml.
use serde_json::{json, Value};
let rule = json!({
"===": [
2,
{ "var": "foo" }
]
});
let data = json!({ "foo": 2 });
assert_eq!(jsonlogic::apply(&rule, &data), Ok(Value::Bool(true)));
let data = json!({ "foo": 3 });
assert_eq!(jsonlogic::apply(&rule, &data), Ok(Value::Bool(false)));
See the examples directory for more usage examples.
jsonlogic_rs supports all JsonLogic operations. For detailed informations about all operations and their arguments, head over to Supported Operations on jsonlogic.com.
For Rust usage examples and edge cases have a look at the linked tests for each operator below.
The library now includes a validation module to ensure JSON Logic rules conform to your requirements:
use jsonlogic::validation::{ValidationConfig, validate, allowed_operators, variable_set, RequireAndWrapper};
use serde_json::json;
// Create a validation configuration
let config = ValidationConfig {
require_and_wrapper: Some(RequireAndWrapper { allow_empty: true }),
};
// Validate a rule
let rule = json!({
"and": [
{"==": [{"var": "age"}, 18]},
{"==": [{"var": "name"}, Joe]},
]
});
match validate(&rule, &config) {
Ok(_) => println!("Rule is valid!"),
Err(err) => println!("Validation failed: {} at {}", err.message, err.path),
}
The validation module lets you:
Future versions will include more validation options, such as: