I've created a Rust implementation of JSONLogic, a standard for writing portable logic rules as JSON. The library features an AST-based evaluation system with a two-phase execution model: first parsing expressions into a pre-compiled AST via from_value
, then executing them with the apply
function.
What is JSONLogic?
JSONLogic enables you to write logical expressions as JSON objects that can be easily stored and transferred between different systems.
Features
- Full implementation of the JSONLogic specification
- AST-based evaluation for efficient execution
- Zero-copy deserialization with serde
- Comprehensive test coverage, including all official test cases
- Pure Rust implementation with minimal dependencies
- Support for custom operations
Why Another Implementation?
While there are several JSONLogic implementations in other languages, I wanted to create a robust, type-safe implementation that leverages Rust's strong guarantees and performance characteristics.
Example Usage
use datalogic_rs::*;
use serde_json::json;
fn main() {
// Parse and compile the expression
let logic = json!({ "max": {"var": "data"} });
let rule = Rule::from_value(&logic).unwrap();
// Apply it to data
let data = json!({ "data": [1, 2, 3] });
let result = JsonLogic::apply(&rule, &data).unwrap();
println!("Result: {}", result);
}
What I'm Looking For
- Code structure and organization feedback
- Performance optimization suggestions
- API design improvements
- Rust idiom and best practices review
- Error handling approaches
Repository
Check it out at datalogic-rs
Would love to hear your thoughts and suggestions for improvement. Thanks in advance!