Table of Contents

Example documents

The RuleWright repository ships a tour of the rule format as twenty-five documents, each with a description explaining what it shows. The repository's own tests evaluate every one, and so does this site's build: each document below validated and loaded against the engine the site documents.

Every document, loaded

The site's build loads each example with the built-in functions registered, plus the two registrations the newest examples name: a RoundTo value function and a setIfHigher custom action:

01-quickstart-single-rule.json           rule             1 rule(s)
02-rule-set-priority.json                rule set         3 rule(s)
03-string-operators.json                 rule set         3 rule(s)
04-collection-operators.json             rule set         3 rule(s)
05-null-and-coalesce.json                rule set         2 rule(s)
06-nested-logic.json                     rule             1 rule(s)
07-computed-values.json                  rule set         2 rule(s)
08-arithmetic-operators.json             rule             1 rule(s)
09-accumulators-risk-scoring.json        rule set         4 rule(s)
10-decision-table-first.json             decision table   4 rule(s)
11-decision-table-collect-scoring.json   decision table   3 rule(s)
12-custom-function.json                  rule             1 rule(s)
13-if-else-append.json                   rule set         2 rule(s)
14-if-else-decision-table.json           decision table   2 rule(s)
15-condition-side-expression.json        rule             1 rule(s)
16-else-and-remove.json                  rule set         3 rule(s)
17-disabled-rule.json                    rule set         2 rule(s)
18-builtin-functions.json                rule             1 rule(s)
19-decision-table-computed-cell.json     decision table   3 rule(s)
20-collection-operators.json             rule set         5 rule(s)
21-stop-after-first-match.json           rule set         3 rule(s)
22-scoped-params.json                    rule set         3 rule(s)
23-value-functions.json                  rule set         2 rule(s)
24-failure-messages.json                 rule set         3 rule(s)
25-custom-action.json                    rule set         2 rule(s)

The documents

Download Shows
01-quickstart-single-rule.json The smallest document: one rule, nested AND / OR, two setOutput actions.
02-rule-set-priority.json A rule set, where priority sets evaluation order and so decides which output wins the merge.
03-string-operators.json Contains, StartsWith, EndsWith and MatchesRegex, all ordinal.
04-collection-operators.json In and NotIn against a closed set.
05-null-and-coalesce.json IsNull / IsNotNull, and coalesce to supply defaults.
06-nested-logic.json AND, OR and NOT nested to any depth.
07-computed-values.json Outputs computed from fact fields with multiply, subtract and concat.
08-arithmetic-operators.json Every arithmetic operator.
09-accumulators-risk-scoring.json addToOutput and appendToOutput building a score and a list across rules.
10-decision-table-first.json A decision table with hitPolicy: "first".
11-decision-table-collect-scoring.json A collect table feeding accumulators.
12-custom-function.json The custom operator calling a registered function (IsWeekend).
13-if-else-append.json If / else written as a rule and its NOT twin, the way to do it before else existed.
14-if-else-decision-table.json The same if / else as a first decision table, with the condition written once.
15-condition-side-expression.json A computed left-hand side: Order.Total / Order.ItemCount > 25.
16-else-and-remove.json else actions, and removeOutput retracting an earlier rule's output.
17-disabled-rule.json enabled: false retiring a rule without deleting it.
18-builtin-functions.json Built-in functions: IsEmail, EqualsIgnoreCase, DivisibleBy, IsPositive.
19-decision-table-computed-cell.json A decision table whose then cell is an expression.
20-collection-operators.json Any, All and None, "$" for scalar elements, and count.
21-stop-after-first-match.json stopAfterFirstMatch: a fallthrough ladder where the first match decides.
22-scoped-params.json Scoped params: params on the set and on a rule, { "param": … } references, and shadowing.
23-value-functions.json A value function called with { "call": "RoundTo", … }, in an action value and as a computed left-hand side.
24-failure-messages.json failureMessage: each rule's explanation for saying no, surfaced on result.Failures.
25-custom-action.json A custom action type (setIfHigher) keeping the highest of several bids.

The facts they expect

The examples read a fact shaped roughly like this. A dictionary fact can leave fields out, and they read as null. A typed fact must have every member a rule names.

Customer { Name, Age, Tier, IsVip, LoyaltyYears, Country, Email, PostCode }
Order    { Total, ItemCount, Weight, Coupon, Category, ShippingCost, PlacedOn,
           DiscountApplied, Lines, Tags }

Try them in the rule builder

The RuleWright repository also has a browser-based rule builder that opens any of these documents on a drag-and-drop canvas, validates it and runs it against a test fact, using the real engine compiled to WebAssembly. Design and test rules in the visual builder walks through it.