| Crates.io | product-farm-json-logic |
| lib.rs | product-farm-json-logic |
| version | 0.2.0 |
| created_at | 2025-12-30 15:21:28.304173+00 |
| updated_at | 2026-01-04 01:29:34.873331+00 |
| description | JSON Logic parser, AST, and bytecode compiler for Product-FARM |
| homepage | |
| repository | https://github.com/ayushmaanbhav/product-farm |
| max_upload_size | |
| id | 2012817 |
| size | 245,134 |
High-performance JSON Logic implementation with bytecode compilation and a register-based VM.
product-farm-json-logic is a blazing-fast JSON Logic evaluator featuring:
| Mode | Time | Throughput |
|---|---|---|
| AST Interpretation | ~1.15μs | 870K/sec |
| Bytecode Execution | ~330ns | 3M/sec |
| Improvement | 3.5x | 3.5x |
| Complexity | AST | Bytecode | Speedup |
|---|---|---|---|
| Single if/else | 1.8μs | 450ns | 4.0x |
| Nested (3 levels) | 3.2μs | 680ns | 4.7x |
| Multiple (5 branches) | 4.1μs | 820ns | 5.0x |
This crate is part of Product-FARM, an enterprise-grade rule engine featuring:
[dependencies]
product-farm-json-logic = "0.2"
use product_farm_json_logic::{JsonLogicEvaluator, CachedExpression};
use product_farm_core::Value;
use serde_json::json;
// Create an evaluator
let mut evaluator = JsonLogicEvaluator::new();
// Parse and cache an expression (auto-compiles to bytecode if complex)
let expr = CachedExpression::new(json!({
"if": [
{"<": [{"var": "age"}, 25]},
{"*": [{"var": "base_rate"}, 1.5]},
{"<": [{"var": "age"}, 35]},
{"*": [{"var": "base_rate"}, 1.2]},
{"var": "base_rate"}
]
}));
// Evaluate with data
let data = Value::Object(hashbrown::HashMap::from([
("age".into(), Value::Number(30.0)),
("base_rate".into(), Value::Number(100.0)),
]));
let result = evaluator.evaluate_cached_value(&expr, &data)?;
// result = 120.0 (base_rate * 1.2 for age 30)
+, -, *, /, %, min, max
==, !=, <, <=, >, >=, ===, !==
and, or, !, !!, if, ?:
cat, substr, in
map, filter, reduce, all, some, none, merge
var, missing, missing_some
JSON Logic Expression
│
▼
┌─────────┐
│ Parser │ ──────► AST
└─────────┘
│
▼ (if nodes > 5)
┌──────────┐
│ Compiler │ ──────► Bytecode
└──────────┘
│
▼
┌─────────┐
│ VM │ ──────► Result
└─────────┘
| Crate | Description |
|---|---|
| product-farm-core | Core domain types |
| product-farm-rule-engine | DAG executor |
| product-farm-farmscript | Human-friendly DSL |
MIT License - see LICENSE for details.