1 unstable release

0.5.5 Jul 30, 2025

#1005 in Parser implementations

Download history 75/week @ 2025-08-13 80/week @ 2025-08-20 44/week @ 2025-08-27 78/week @ 2025-09-03 60/week @ 2025-09-10 33/week @ 2025-09-17 109/week @ 2025-09-24 81/week @ 2025-10-01 73/week @ 2025-10-08 48/week @ 2025-10-15 66/week @ 2025-10-22 92/week @ 2025-10-29 71/week @ 2025-11-05 99/week @ 2025-11-12 95/week @ 2025-11-19 123/week @ 2025-11-26

418 downloads per month
Used in 3 crates (2 directly)

MIT license

180KB
4K SLoC

jsonlogic_rs   Build Status Latest Version

A JsonLogic implementation in Rust.

To use this library, add

[dependencies]
jsonlogic = "0.5"

to your Cargo.toml.

Usage

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.

Operations

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.

Validation

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:

  • Require rules to be wrapped in an 'and' block (with option to allow empty rules)

Future versions will include more validation options, such as:

  • Restrict which operators can be used
  • Limit the depth of the rule's expression tree
  • Control which variables can be accessed
  • Ensure required variables are present
  • Apply custom validation logic

Dependencies

~3–4.5MB
~95K SLoC