Try the JSONLogic Online Debugger to interactively test your rules
datalogic-rs is a high-performance Rust implementation of JSONLogic for evaluating logical rules expressed as JSON. It provides a fast, memory-efficient, and thread-safe way to evaluate complex business rules, feature flags, dynamic pricing logic, and more.
The same engine ships across runtimes: Rust, Node.js (native), JavaScript / TypeScript (WebAssembly), Python, Go, JVM (Java/Kotlin/Scala), .NET, PHP, and a React visual debugger. Author the rule once; evaluate it anywhere. For the cross-runtime overview and per-binding install instructions, see the repository README.
v5 is here. v5 is a breaking release that renames
DataLogic→Engine, makes one-shot evaluation string-based, switches custom operators to a pre-evaluated arena API, and removes the implicitserde_jsondependency from the default build. v5 is a hard cliff — there is no compatibility shim. See the Migration Guide for the conceptual overview and the repo-rootMIGRATION.mdfor the full v4 → v5 cookbook.
Why datalogic-rs?
- Fast - OpCode-based dispatch with compile-time optimization, plus arena allocation for zero-copy reads
- Thread-Safe - Wrap
LogicinArcand share across threads (or useEngine::compile_arcto do it in one step) - Zero
unsafe- The crate enforces#![forbid(unsafe_code)] - serde_json-free by default - The string-based API needs no
serde_jsondependency; opt into theserde_jsonfeature when you needserde_json::Valueinterop or the typedeval_into::<T>paths - Five-tier API ladder - module-level helpers (
datalogic_rs::eval_str, …) for one-shot use,Enginefor configured workloads,Sessionfor compile-once / evaluate-many hot loops, rawevaluate(&Bump)for zero-copy result pipelines, andEngine::trace()for debugging - Cross-runtime - same rules, same semantics across Rust, WASM, Python, Go, and the React debugger
- Extensible - Register custom operators on an
EngineBuilder - Feature-Rich - 59 built-in operators including datetime, regex, and error handling
- Fully Compliant - Passes the official JSONLogic test suite
How It Works
datalogic-rs uses a two-phase approach:
-
Compilation: Your JSON logic is parsed and compiled into a reusable
Logic. This phase:- Assigns OpCodes to built-in operators for fast dispatch
- Pre-evaluates constant expressions
- Analyzes structure for templating mode
-
Evaluation: The compiled logic is evaluated against your data with:
- Direct OpCode dispatch (no string lookups at runtime)
- Arena-allocated
&DataValue<'a>results that can borrow zero-copy from the input - Context stack for nested operations (
map,filter,reduce)
Quick Example
#![allow(unused)]
fn main() {
// One-shot evaluation: returns a JSON string.
let result = datalogic_rs::eval_str(
r#"{">": [{"var": "age"}, 18]}"#,
r#"{"age": 21}"#,
).unwrap();
assert_eq!(result, "true");
}
For repeated evaluation, compile once and reuse via a session:
#![allow(unused)]
fn main() {
use datalogic_rs::Engine;
let engine = Engine::new();
let compiled = engine.compile(r#"{">": [{"var": "age"}, 18]}"#).unwrap();
let mut session = engine.session();
let r1 = session.eval_str(&compiled, r#"{"age": 21}"#).unwrap();
let r2 = session.eval_str(&compiled, r#"{"age": 16}"#).unwrap();
assert_eq!(r1, "true");
assert_eq!(r2, "false");
session.reset();
}
What is JSONLogic?
JSONLogic is a standard for expressing logic rules as JSON. This makes it:
- Portable: Rules can be stored in databases, sent over APIs, or embedded in configuration
- Language-agnostic: The same rules work across different implementations
- Human-readable: Rules are easier to understand than arbitrary code
- Safe: Rules can be evaluated without arbitrary code execution
A JSONLogic rule is a JSON object where:
- The key is the operator name
- The value is an array of arguments
{"operator": [arg1, arg2, ...]}
For example:
{"and": [
{">": [{"var": "age"}, 18]},
{"==": [{"var": "country"}, "US"]}
]}
This rule checks if age > 18 AND country == "US".
Next Steps
- Installation - Add datalogic-rs to your project
- Quick Start - Get up and running in minutes
- Migration Guide - Move from v4 to v5
- Operators - Explore all 59 built-in operators
- API Reference - Public Rust types and the 5-tier API model
Using another language? This site focuses on the Rust crate; for Node.js (native), JavaScript / TypeScript (WASM), Python, Go, JVM, .NET, PHP, and React, jump straight to the per-binding README in the repo root.