| Crates.io | json-eval-rs |
| lib.rs | json-eval-rs |
| version | 0.0.60 |
| created_at | 2025-10-30 04:55:02.233066+00 |
| updated_at | 2026-01-21 09:33:51.499063+00 |
| description | High-performance JSON Logic evaluator with schema validation and dependency tracking. Built on blazing-fast Rust engine. |
| homepage | |
| repository | https://github.com/byrizki/jsoneval-rs |
| max_upload_size | |
| id | 1907720 |
| size | 3,168,239 |
High-performance JSON Logic evaluation library with schema validation and multi-platform bindings
json-eval-rs is a blazing-fast JSON Logic evaluator written in Rust, featuring a custom-built compiler, intelligent caching, parallel evaluation, and comprehensive schema validation. It provides seamless integration across multiple platforms through native bindings.
simd-json for ultra-fast JSON parsing$ref referencesð Comprehensive Operator Documentation - Complete guide to all 80+ available operators:
and, or, if, etc.)==, <, >, etc.)+, -, *, /, etc.)cat, substr, search, etc.)round, abs, max, etc.)today, dateformat, etc.)map, filter, reduce, etc.)VALUEAT, INDEXAT, etc.)missing, RANGEOPTIONS, etc.)[dependencies]
json-eval-rs = "0.0.60"
dotnet add package JsonEvalRs
yarn install @json-eval-rs/web
yarn install @json-eval-rs/react-native
Selective evaluation allows you to re-evaluate only specific fields in your schema, significantly improving performance for partial updates.
Benefits:
Rust Example:
use json_eval_rs::JSONEval;
let mut eval = JSONEval::new(&schema, None, Some(&data))?;
// Full evaluation
eval.evaluate(&data, None, None)?;
// Later, selectively re-evaluate only specific fields
let paths = vec![
"user.email".to_string(),
"billing.total".to_string()
];
eval.evaluate(&updated_data, None, Some(&paths))?;
C# Example:
using JsonEvalRs;
var eval = new JSONEval(schema);
eval.Evaluate(data);
// Selective re-evaluation
var paths = new[] { "user.email", "billing.total" };
eval.Evaluate(updatedData, paths: paths);
Web/TypeScript Example:
import { JSONEval } from "@json-eval-rs/web";
const eval = new JSONEval({ schema: JSON.stringify(schema) });
await eval.evaluateJS({ data: JSON.stringify(data) });
// Selective re-evaluation
await eval.evaluateJS({
data: JSON.stringify(updatedData),
paths: ["user.email", "billing.total"]
});
How it works:
"field.nested.property")Configure timezone offset for all date/time operations without external dependencies.
Benefits:
Rust Example:
use json_eval_rs::JSONEval;
let mut eval = JSONEval::new(&schema, None, None)?;
// Set to UTC+7 (Bangkok, Jakarta) - 420 minutes offset
eval.set_timezone_offset(Some(420));
eval.evaluate(&data, None, None)?;
// Reset to UTC
eval.set_timezone_offset(None);
C# Example:
using JsonEvalRs;
var eval = new JSONEval(schema);
// Set timezone to UTC+7 (420 minutes)
eval.SetTimezoneOffset(420);
eval.Evaluate(data);
// Reset to UTC
eval.SetTimezoneOffset(null);
Web/TypeScript Example:
import { JSONEval } from "@json-eval-rs/web";
const eval = new JSONEval({ schema: JSON.stringify(schema) });
// Set timezone to UTC+7
eval.setTimezoneOffset(420);
await eval.evaluateJS({ data: JSON.stringify(data) });
// Reset to UTC
eval.setTimezoneOffset(null);
Common Timezone Offsets:
0 or null420540-300-48060Affected Operations:
TODAY - Current date at midnight in the specified timezoneNOW - Current timestamp in the specified timezoneDATEFORMAT - Formats dates using the timezone offsetuse json_eval_rs::JSONEval;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let schema = r#"{
"type": "object",
"properties": {
"name": {
"rules": {
"required": { "value": true, "message": "Name is required" }
}
}
}
}"#;
let mut eval = JSONEval::new(schema, None, None)?;
let data = r#"{"name": "John Doe"}"#;
eval.evaluate(data, None)?;
let result = eval.get_evaluated_schema(false);
// Validate the data
let validation = eval.validate(data, None, None)?;
if !validation.has_error {
println!("â
Data is valid!");
} else {
println!("â Validation errors: {:?}", validation.errors);
}
Ok(())
}
using JsonEvalRs;
var schema = @"{
""type"": ""object"",
""properties"": {
""age"": {
""rules"": {
""minValue"": { ""value"": 18, ""message"": ""Must be 18 or older"" }
}
}
}
}";
using (var eval = new JSONEval(schema))
{
var data = @"{""age"": 25}";
var result = eval.Evaluate(data);
var validation = eval.Validate(data);
if (!validation.HasError)
{
Console.WriteLine("â
Data is valid!");
}
}
import { JSONEval } from "@json-eval-rs/web";
const schema = {
type: "object",
properties: {
email: {
rules: {
required: { value: true, message: "Email is required" },
pattern: {
value: "^[^@]+@[^@]+\\.[^@]+$",
message: "Invalid email format",
},
},
},
},
};
const eval = new JSONEval({ schema: JSON.stringify(schema) });
const data = { email: "user@example.com" };
const result = await eval.evaluateJS({ data: JSON.stringify(data) });
const validation = await eval.validate({ data: JSON.stringify(data) });
if (!validation.has_error) {
console.log("â
Data is valid!");
}
eval.free(); // Clean up memory
import { useJSONEval } from "@json-eval-rs/react-native";
function ValidationForm() {
const eval = useJSONEval({ schema });
const [formData, setFormData] = useState({ name: "", age: "" });
const [errors, setErrors] = useState({});
const validateForm = async () => {
if (!eval) return;
const validation = await eval.validate({
data: JSON.stringify(formData),
});
setErrors(validation.errors || {});
};
return (
<View>
<TextInput
value={formData.name}
onChangeText={(name) => setFormData({ ...formData, name })}
onBlur={validateForm}
/>
{errors.name && (
<Text style={{ color: "red" }}>{errors.name.message}</Text>
)}
</View>
);
}
| Operation | json-eval-rs | Native JS | Improvement |
|---|---|---|---|
| Parse Complex Schema | 3ms | 15ms | 5x faster |
| Evaluate 1000 Rules | 8ms | 45ms | 5.6x faster |
| Validate Large Form | 2ms | 12ms | 6x faster |
| Cache Hit Lookup | 0.1ms | 2ms | 20x faster |
Benchmarks run on Intel i7 with complex real-world schemas
Arc<Value> to avoid deep cloningrayon (disabled for WASM)simd-json for ultra-fast JSON parsingThe library includes comprehensive examples demonstrating various use cases:
Simple evaluation with automatic scenario discovery:
# Run all scenarios
cargo run --example basic
# Run specific scenario
cargo run --example basic zcc
# Enable comparison with expected results
cargo run --example basic --compare
Advanced benchmarking with ParsedSchema caching and concurrent testing:
# Run with 100 iterations
cargo run --example benchmark -- -i 100 zcc
# Use ParsedSchema for efficient caching
cargo run --release --example benchmark -- --parsed -i 100 zcc
# Test concurrent evaluations (4 threads, 10 iterations each)
cargo run --example benchmark -- --parsed --concurrent 4 -i 10
# Full benchmarking suite with comparison
cargo run --release --example benchmark -- --parsed -i 100 --compare
For more details, see examples/README.md.
A powerful CLI tool for direct schema evaluation with parsed schema inspection:
# Simple evaluation
cargo run --bin json-eval-cli -- schema.json -d data.json
# With comparison and ParsedSchema
cargo run --bin json-eval-cli -- schema.json -d data.json \
-c expected.json --parsed -i 100
# Inspect parsed schema structure
cargo run --bin json-eval-cli -- schema.json -d data.json \
--parsed --no-output \
--print-sorted-evaluations \
--print-dependencies
# All parsed schema information
cargo run --bin json-eval-cli -- schema.json -d data.json \
--parsed --print-all
# Full options with MessagePack support
cargo run --bin json-eval-cli -- schema.bform \
--data data.bform \
--compare expected.json \
--compare-path "$.$params.others" \
--parsed \
--iterations 100 \
--output result.json
Parsed Schema Inspection Flags:
--print-sorted-evaluations - Show evaluation batches for parallel execution--print-dependencies - Show dependency graph between evaluations--print-tables - Show table definitions--print-evaluations - Show all compiled logic expressions--print-all - Show all parsed schema informationRun cargo run --bin json-eval-cli -- --help for full documentation.
ð JSON Evaluation Benchmark
==============================
Scenario: zcc
Schema: samples/zcc.json
Data: samples/zcc-data.json
Loading files...
Running evaluation...
Schema parsing & compilation: 3.2ms
Total evaluation time: 12.4ms
Average per iteration: 124Ξs
Cache: 1,247 entries, 8,932 hits, 89 misses (99.0% hit rate)
âąïļ Execution time: 15.6ms
â
Results saved:
- samples/zcc-evaluated-schema.json
- samples/zcc-parsed-schema.json
- samples/zcc-evaluated-value.json
| Platform | Technology | Performance | Bundle Size |
|---|---|---|---|
| Rust | Native | Native | N/A |
| C# / .NET | P/Invoke FFI | Native | ~2MB |
| Web | WebAssembly | Near-native | ~450KB gzipped |
| React Native | Native Modules (JSI) | Native | Native code |
# Clone the repository
git clone https://github.com/byrizki/jsoneval-rs.git
cd json-eval-rs
# Build the core library
cargo build --release
# Run tests
cargo test
# Build all language bindings
./build-bindings.sh all
# Run CLI tool with examples
cargo run --bin json-eval-cli
We welcome contributions! Please see our Contributing Guidelines for details.
cargo buildcargo testcargo fmt and cargo clippy# Build specific binding
./build-bindings.sh csharp # C# only
./build-bindings.sh web # Web only
./build-bindings.sh react-native # React Native only
# Package for publishing
./build-bindings.sh package
json-eval-rs uses an extended JSON Schema format with evaluation rules:
{
"type": "object",
"properties": {
"fieldName": {
"type": "string",
"rules": {
"required": {
"value": true,
"message": "This field is required"
},
"minLength": {
"value": 3,
"message": "Must be at least 3 characters"
},
"pattern": {
"value": "^[A-Za-z]+$",
"message": "Only letters allowed"
}
},
"condition": {
"hidden": { "==": [{ "var": "other.field" }, "hide"] },
"disabled": { "!=": [{ "var": "user.role" }, "admin"] }
}
}
},
"$layout": {
"elements": [
{
"type": "input",
"$ref": "#/properties/fieldName"
}
]
}
}
required: Field must have a valueminLength/maxLength: String/array length validationminValue/maxValue: Numeric range validationpattern: Regular expression validationThe library provides detailed error information:
match eval.validate(data, None, None) {
Ok(validation) => {
if validation.has_error {
for (field, error) in validation.errors {
println!("Field '{}': {} ({})", field, error.message, error.rule_type);
}
}
},
Err(e) => eprintln!("Validation error: {}", e),
}
This project is licensed under the MIT License - see the LICENSE file for details.
For commercial support, consulting, or custom development, please contact us at support@example.com.
â Star this repository if you find it useful!