Repository navigation
Getting Started
github-actions[bot] edited this page Nov 29, 2026
·
1 revision
-
.NET 10.0 or later (
net10.0) - Fully compatible with NativeAOT and IL trimming
dotnet add package Celly.JsonCelly.Json transitively references Celly and uses only System.Text.Json from the .NET BCL — no additional third-party dependencies.
Compile your CEL expression once and reuse the resulting CelProgram across requests:
using System.Text.Json;
using Celly;
using Celly.Json;
CelProgram program = CelEnv.Default.Compile("user.active && user.age >= 18 && 'admin' in user.roles");
using JsonDocument doc = JsonDocument.Parse("""
{
"user": {
"active": true,
"age": 32,
"roles": ["viewer", "admin"]
}
}
""");
// Typed convenience helper (throws CelEvaluationException on CEL error or non-bool)
bool allowed = program.EvalJsonBool(doc);
// Or inspect the raw CelValue directly
var rawResult = program.EvalJson(doc);| Input Type | Usage | Notes |
|---|---|---|
JsonDocument / JsonElement
|
program.EvalJson(doc) |
Fastest for read-only payloads; zero dictionary allocation. |
JsonObject |
program.EvalJson(jsonObj) |
Fastest overall (~187 ns) when you already have a JsonNode DOM. |
string / ReadOnlyMemory<byte>
|
program.EvalJson(jsonString) |
Parses, evaluates, and safely detaches any JSON-backed return value before disposing the JsonDocument. |
Reusable JsonElementActivation
|
activation.Reset(doc.RootElement) |
Best for tight loops and high-throughput request pipelines. |
Instead of manually casting CelValue and checking IsError, use the typed helpers:
bool isAllowed = program.EvalJsonBool(doc);
long count = countProgram.EvalJsonInt64(doc);
double total = totalProgram.EvalJsonDouble(doc);
string label = labelProgram.EvalJsonString(doc);Each helper throws CelEvaluationException with a clear message if the expression evaluates to a CEL ErrorValue (e.g., division by zero or missing key) or returns a different CEL type.
- Evaluating JSON — Activations, number semantics, mixed bindings, and NDJSON streaming.
- JSON Schema Type Checking — Validate expressions at compile time against JSON Schemas or C# DTOs.
Celly.Json — High-performance System.Text.Json adapter for Celly (.NET 10, NativeAOT-ready, MIT License).