Example Templates
27 pre-built JSONLogic rules across 7 categories
All Examples
Showing 27 examples
LLM Model Router
Route to different AI models based on task complexity and user tier
{ "if": [ { ">=": [ { "var": "tokens" }, 5000 ] }, "claude-sonnet", { "if": [ { "==": [ { "var": "user.tier" }, "premium" ] }, "claude-sonnet", "claude-haiku" ] } ] }
{ "tokens": 3000, "user": { "tier": "free" } }
"claude-haiku"
Dynamic Prompt Selection
Choose prompt variant based on user preferences and context
{ "if": [ { "and": [ { "==": [ { "var": "user.language" }, "es" ] }, { "==": [ { "var": "task" }, "translate" ] } ] }, "prompt_spanish_translation", { "if": [ { "==": [ { "var": "user.verbose" }, true ] }, "prompt_detailed", "prompt_concise" ] } ] }
{ "user": { "language": "en", "verbose": true }, "task": "summarize" }
"prompt_detailed"
Content Safety Gate
Block certain topics or enable guardrails based on user type
{ "if": [ { "or": [ { "==": [ { "var": "user.age" }, null ] }, { "<": [ { "var": "user.age" }, 18 ] } ] }, true, false ] }
{ "user": { "age": 16 } }
true
Age Verification
Check if user meets minimum age requirement
{ ">=": [ { "var": "age" }, 18 ] }
{ "age": 21 }
true
Premium User Discount
Apply discount if user is premium and order exceeds threshold
{ "if": [ { "and": [ { "==": [ { "var": "user.tier" }, "premium" ] }, { ">": [ { "var": "order.total" }, 100 ] } ] }, { "*": [ { "var": "order.total" }, 0.9 ] }, { "var": "order.total" } ] }
{ "user": { "tier": "premium" }, "order": { "total": 150 } }
135
Business Hours Check
Verify if current hour is within business hours
{ "and": [ { ">=": [ { "var": "hour" }, 9 ] }, { "<": [ { "var": "hour" }, 17 ] } ] }
{ "hour": 14 }
true
Multi-Condition Approval
Approve request if user meets multiple criteria
{ "and": [ { ">=": [ { "var": "user.accountAge" }, 30 ] }, { ">=": [ { "var": "user.creditScore" }, 650 ] }, { "<=": [ { "var": "requestAmount" }, 5000 ] } ] }
{ "user": { "accountAge": 45, "creditScore": 720 }, "requestAmount": 3000 }
true
Array Some Check
Check if some items in array meet a condition (e.g., any item qty > 1)
{ "some": [ { "var": "items" }, { ">": [ { "var": "qty" }, 1 ] } ] }
{ "items": [ { "name": "apple", "qty": 1 }, { "name": "banana", "qty": 3 } ] }
true
Array All Check
Verify that all items in array meet a condition
{ "all": [ { "var": "items" }, { ">=": [ { "var": "price" }, 0 ] } ] }
{ "items": [ { "item": "apple", "price": 1.5 }, { "item": "banana", "price": 2 } ] }
true
Filter Expensive Items
Filter array to keep only items above price threshold
{ "filter": [ { "var": "products" }, { ">": [ { "var": "price" }, 100 ] } ] }
{ "products": [ { "name": "Laptop", "price": 999 }, { "name": "Mouse", "price": 25 }, { "name": "Monitor", "price": 450 } ] }
[ { "name": "Laptop", "price": 999 }, { "name": "Monitor", "price": 450 } ]
Extract Names from Array
Map over array to extract specific field from each object
{ "map": [ { "var": "users" }, { "var": "name" } ] }
{ "users": [ { "name": "Alice", "age": 30 }, { "name": "Bob", "age": 25 } ] }
[ "Alice", "Bob" ]
Sum Array Values
Use reduce to calculate total of array values
{ "reduce": [ { "var": "numbers" }, { "+": [ { "var": "current" }, { "var": "accumulator" } ] }, 0 ] }
{ "numbers": [ 1, 2, 3, 4, 5 ] }
15
Array None Check
Verify that no items in array meet a condition
{ "none": [ { "var": "items" }, { "<": [ { "var": "stock" }, 0 ] } ] }
{ "items": [ { "name": "apple", "stock": 10 }, { "name": "banana", "stock": 5 } ] }
true
Merge Arrays
Combine multiple arrays into one
{ "merge": [ { "var": "list1" }, { "var": "list2" } ] }
{ "list1": [ "apple", "banana" ], "list2": [ "cherry", "date" ] }
[ "apple", "banana", "cherry", "date" ]
String Concatenation
Combine multiple strings into one
{ "cat": [ { "var": "firstName" }, " ", { "var": "lastName" } ] }
{ "firstName": "John", "lastName": "Doe" }
"John Doe"
Extract Substring
Extract portion of string using substr operation
{ "substr": [ { "var": "text" }, 0, 5 ] }
{ "text": "Hello World" }
"Hello"
String Contains Check
Check if a substring exists in a string
{ "in": [ "hello", { "var": "message" } ] }
{ "message": "hello world" }
true
Missing Fields Validation
Check if required fields are present in data
{ "if": [ { "missing": [ "firstName", "lastName", "email" ] }, { "cat": [ "Missing required fields: ", { "missing": [ "firstName", "lastName", "email" ] } ] }, "All fields present" ] }
{ "firstName": "Jane", "email": "[email protected]" }
"Missing required fields: lastName"
Value in Array Check
Check if a value exists in an array
{ "in": [ { "var": "status" }, [ "active", "pending", "approved" ] ] }
{ "status": "pending" }
true
Addition
Add multiple numbers together
{ "+": [ { "var": "a" }, { "var": "b" }, { "var": "c" } ] }
{ "a": 10, "b": 20, "c": 5 }
35
Subtraction
Subtract one number from another
{ "-": [ { "var": "total" }, { "var": "discount" } ] }
{ "total": 100, "discount": 15 }
85
Multiplication
Multiply numbers together
{ "*": [ { "var": "price" }, { "var": "quantity" } ] }
{ "price": 25.5, "quantity": 4 }
102
Division
Divide one number by another
{ "/": [ { "var": "total" }, { "var": "count" } ] }
{ "total": 100, "count": 4 }
25
Modulo (Remainder)
Get remainder of division operation
{ "%": [ { "var": "number" }, 2 ] }
{ "number": 17 }
1
Min and Max Values
Find minimum and maximum from numbers
{ "max": [ { "var": "scores" } ] }
{ "scores": [ 85, 92, 78, 95, 88 ] }
95
Nested Conditionals
Complex decision tree with multiple if-then-else branches
{ "if": [ { "<": [ { "var": "age" }, 13 ] }, "child", { "if": [ { "<": [ { "var": "age" }, 20 ] }, "teenager", { "if": [ { "<": [ { "var": "age" }, 65 ] }, "adult", "senior" ] } ] } ] }
{ "age": 45 }
"adult"
Logarithm
Calculate logarithm of a number
{ "log": [ { "var": "value" } ] }
{ "value": 100 }
2
Ready to build your own rules?
Open Visual Editor