Repository navigation
Home
github-actions[bot] edited this page Nov 29, 2026
·
2 revisions
Celly.Json is a high-performance, minimal-allocation System.Text.Json adapter, JSON Schema static type checker, and result serializer for Celly — Google's Common Expression Language (CEL) for .NET.
Core Celly evaluates CEL expressions in ~125 ns, but passing raw JSON payloads into it by eagerly converting JsonDocument into nested Dictionary<string, object?> and List<object?> trees allocates tens of kilobytes per request and slows evaluation down by 50–100×.
Celly.Json eliminates that bottleneck:
| Workload | Naive Eager Dictionary | Celly.Json |
Improvement |
|---|---|---|---|
Policy rule on 15 KB JSON (JsonDocument) |
19,375 ns / 85,416 B
|
269 ns / 384 B |
72× faster, 222× less alloc |
Policy rule on 15 KB JSON (JsonObject) |
19,375 ns / 85,416 B
|
187 ns / 296 B |
103× faster, 288× less alloc |
100-item filter comprehension |
55,508 ns / 214,680 B
|
8,504 ns / 14,992 B |
6.5× faster, 14.3× less alloc |
-
Zero eager materialization — Evaluates directly over
JsonElement,JsonDocument,JsonObject, andJsonArray, decoding only the fields an expression actually reads. -
JSON Schema static type checking — Compile Draft-07 / Draft 2020-12 JSON Schemas (or .NET types via
JsonSchemaEnv.Create<T>()) into Celly static type declarations to catch typos and type mismatches before runtime. -
Schema-driven static cost estimation — Feed JSON Schema
maxLength/maxItems/maxPropertiesbounds directly intoCelEnv.EstimateCost(...)to sandbox untrusted user rules. -
In-expression JSON helpers —
JsonLibraryaddsjson.parse(string)andjson.stringify(dyn)inside CEL expressions. -
Direct CEL → JSON serialization — Write
CelValueresults straight toUtf8JsonWriter, JSON strings, UTF-8 bytes, orJsonNode. -
Zero extra dependencies & NativeAOT ready — Targets
.NET 10, depends only onCellyand the BCL (System.Text.Json).
using System.Text.Json;
using Celly;
using Celly.Json;
// Compile once, evaluate millions of times
CelProgram rule = CelEnv.Default.Compile("user.age >= 18 && 'admin' in user.roles");
using JsonDocument doc = JsonDocument.Parse("""
{ "user": { "age": 32, "roles": ["viewer", "admin"] } }
""");
bool allowed = rule.EvalJsonBool(doc); // true (~270 ns, zero Dictionary allocations)-
New to
Celly.Json? Start with Getting Started. - Evaluating dynamic JSON payloads & NDJSON streams? See Evaluating JSON.
- Want compile-time validation of expressions? See JSON Schema Type Checking.
- Running untrusted user rules? See Cost Estimation & Sandboxing.
-
Need
json.parse()/json.stringify()inside CEL? See JSON Extension Library. - Converting CEL outputs back to JSON? See Serializing CEL Results.
Celly.Json — High-performance System.Text.Json adapter for Celly (.NET 10, NativeAOT-ready, MIT License).