Workflow JSON reference
A workflow is the unit you register with the engine and execute by name. The machine-readable definition is schema/workflow-schema.json; a file that holds several workflows is an array of them (schema/workflow-list-schema.json). The same shapes exist as the C# classes Workflow, Rule, ScopedParam, RuleActions and ActionInfo in RulesEngine.Models.
Property names are case-sensitive when you deserialize with System.Text.Json (the default). Unknown properties are ignored.
Workflow
| Property | Type | Required | Description |
|---|---|---|---|
WorkflowName |
string | yes | Unique name used to execute the workflow. Adding a second workflow with the same name with AddWorkflow fails; use AddOrUpdateWorkflow. |
Rules |
array of Rule | yes, unless WorkflowsToInject is set |
The rules of the workflow. |
WorkflowsToInject |
array of string | no | Names of other registered workflows whose rules are added to this workflow when it is compiled. A workflow can consist only of injected rules. Circular references throw InvalidOperationException. Only the rules are injected, not the other workflow's GlobalParams. |
GlobalParams |
array of ScopedParam | no | Named expressions available to every rule. Evaluated once per execution. Names must be unique. |
RuleExpressionType |
string | no | LambdaExpression (the only value, and the default). |
Rule
A rule is either a leaf rule (it has an Expression) or a nested rule (it has an Operator and child Rules).
| Property | Type | Applies to | Description |
|---|---|---|---|
RuleName |
string | all | Required. Should be unique within the workflow, including injected rules; duplicate names fail when the workflow is first compiled. |
Expression |
string | leaf | Required for a leaf rule. Must evaluate to bool. See the expression language. |
Operator |
string | nested | And, AndAlso, Or or OrElse (not case-sensitive). |
Rules |
array of Rule | nested | Child rules. A rule that has an Operator needs at least one. A leaf rule must not have child rules. |
Enabled |
bool | all | Default true. A disabled rule is not compiled, evaluated or returned. Disabled children of a nested rule are skipped. |
LocalParams |
array of ScopedParam | all | Named expressions available to this rule and its child rules. Names must be unique within the rule. |
ErrorMessage |
string | all | Message copied to the result's ExceptionMessage when the rule fails. May contain $(name) and $(name.path) placeholders. |
SuccessEvent |
string | all | Value passed to the OnSuccess callback of the result extensions. Defaults to the rule name. |
Properties |
object | all | Free-form data you can read back from RuleResultTree.Rule.Properties. |
Actions |
RuleActions | all | Actions to run after the rule is evaluated. |
RuleExpressionType |
string | all | LambdaExpression (the only value, and the default). |
ScopedParam
| Property | Type | Required | Description |
|---|---|---|---|
Name |
string | yes | Identifier that expressions use. Must not collide with the name of an input. |
Expression |
string | yes | An expression. It can use the inputs and every scoped parameter defined before it. |
RuleActions and ActionInfo
| Property | Type | Description |
|---|---|---|
Actions.OnSuccess |
ActionInfo | Runs when the rule succeeds. |
Actions.OnFailure |
ActionInfo | Runs when the rule fails. |
ActionInfo.Name |
string | Name of a built-in or custom action (not case-sensitive). |
ActionInfo.Context |
object | Values passed to the action. See Actions. |
Validation
AddWorkflow and AddOrUpdateWorkflow validate the workflow and throw RuleValidationException for:
- a missing
WorkflowName; - no
Rulesand noWorkflowsToInject; - a rule without
RuleName; - a leaf rule without
Expression, or a rule without anOperatorthat has childRules; - an
Operatorthat is not one of the four allowed values; - duplicate
GlobalParamsnames in a workflow, or duplicateLocalParamsnames in a rule.
Not validated when the workflow is added, and reported later: the syntax of expressions, whether injected workflows exist, duplicate rule names, and whether actions exist.
Example
{
"WorkflowName": "Checkout",
"GlobalParams": [
{ "Name": "isIndia", "Expression": "input1.country == \"india\"" }
],
"Rules": [
{
"RuleName": "Discount10",
"SuccessEvent": "10",
"ErrorMessage": "Order total $(input1.total) is too low.",
"LocalParams": [
{ "Name": "big", "Expression": "input1.total >= 5000" }
],
"Expression": "isIndia AND big",
"Actions": {
"OnSuccess": { "Name": "OutputExpression", "Context": { "expression": "input1.total * 0.9" } }
}
},
{
"RuleName": "EitherCondition",
"Operator": "OrElse",
"Rules": [
{ "RuleName": "Vip", "Expression": "input1.vip == true" },
{ "RuleName": "Large", "Expression": "input1.total > 20000" }
]
}
]
}