Loading...
Loading...
Implement, validate, and test JSONLogic rules for portable business logic. Use when working with JSONLogic syntax, creating rules for conditional logic, validating rule structures, testing rules against data, or converting business requirements to JSONLogic. Triggers on requests to "write jsonlogic", "validate jsonlogic", "create a rule", "business logic as JSON", "conditional logic", or any mention of JSONLogic rules.
npx skill4agent add yonderlab/kota.agent.skills jsonlogic-validator{ "operator": [arguments] }{"==": [1, 1]} // comparison
{"var": "user.name"} // data access
{"and": [{">=": [{"var": "age"}, 18]}, {"var": "active"}]} // compound| Category | Operators |
|---|---|
| Data | |
| Logic | |
| Numeric | |
| Array | |
| String | |
// Requirement: "Premium users over 25 get 20% discount, others get 10%"
{
"if": [
{"and": [
{"==": [{"var": "tier"}, "premium"]},
{">": [{"var": "age"}, 25]}
]},
0.20,
0.10
]
}node scripts/validate-jsonlogic.js '<rule>' '<data>'node scripts/validate-jsonlogic.js '{">=": [{"var": "age"}, 18]}' '{"age": 25}'npm install json-logic-jsnode scripts/test-jsonlogic.js '<rule>' --test-cases '[
{"data": {"age": 25}, "expected": true},
{"data": {"age": 15}, "expected": false}
]'{"var": ["user.name", "Guest"]}{"<=": [0, {"var": "value"}, 100]}{"and": [
{">=": [{"var": "age"}, 18]},
{"==": [{"var": "status"}, "active"]},
{"in": [{"var": "role"}, ["admin", "editor"]]}
]}{"if": [
{">=": [{"var": "score"}, 90]}, "A",
{">=": [{"var": "score"}, 80]}, "B",
{">=": [{"var": "score"}, 70]}, "C",
"F"
]}// Sum: reduce with +
{"reduce": [{"var": "items"}, {"+": [{"var": "accumulator"}, {"var": "current"}]}, 0]}
// Filter: keep matching
{"filter": [{"var": "items"}, {">": [{"var": ""}, 10]}]}
// Any match: some
{"some": [{"var": "items"}, {"==": [{"var": ".status"}, "error"]}]}0[]""null"0"[0]references/jsonlogic-reference.md