Choice States
A Choice state ("Type": "Choice") adds branching logic to a flow.
Choice states must contain a "Choices" field which is an array of
"Choice Rules".
Each Choice Rule contains a boolean expression and a "Next" field, containing
the name of a state to which the flow run should transition if the expression
is true.
Choice states may contain a "Default", the name of a state to choose
if none of the boolean expressions causes a transition. If none of the
Choice Rules matches and a "Default" is not defined, the run will
terminate with an error.
Choice rules are evaluated in order. The first rule which passes is evaluated and selects the next state.
Fields
Choices-
An array of Choice Rules.
Default-
The default state to transition to next if no rule in
"Choices"matches.
Choice Rules
There are many distinct Choice Rules, each of which encodes a different boolean check.
Using And, Or, and Not Choice Rules, these rules can be nested.
Rules must include a Next field, declaring the state to which the
flow run will transition if the rule is matched.
However, nested rules may not include Next — it is allowed and required only
at the top level of the Choices array.
Each rule type requires its own documentation.
"And" Rules
An And rule contains an "And", an array of nested Choice Rules.
The rule evaluates to true if all of the rules in the array evaluate to true.
"Or" Rules
An Or rule contains an "Or", an array of nested Choice Rules.
The rule evaluates to true if any of the rules in the array evaluate to true.
"Not" Rules
An Not rule contains a "Not", a single nested Choice Rule.
The rule evaluates to true if the nested rule evaluates to false.
Variable Rules
A Variable Rule contains two fields.
One is always "Variable", a JSONPath expression which indicates a value in
the state input which is evaluated by this rule.
The other field on a Variable Rule is one of the following:
- BooleanEquals
-
A value,
trueorfalse, to which theVariableis compared. - BooleanEqualsPath
-
A JSONPath expression which indicates the location of a value in the input. The value is used as in
BooleanEquals. - IsBoolean
-
Contains a boolean value. When true, evaluates to true if the
Variableistrueorfalse, false if it has any other value. When false, the meaning is inverted. - IsNull
-
Contains a boolean value. When true, evaluates to true if the
Variableisnull, false if it has any other value. When false, the meaning is inverted. - IsNumeric
-
Contains a boolean value. When true, evaluates to true if the
Variableis an integer or float, false otherwise. When false, the meaning is inverted. - IsPresent
-
Contains a boolean value. When true, evaluates to true if the expression in
Variablepoints to a valid location in the payload, false otherwise. When false, the meaning is inverted. - IsString
-
Contains a boolean value. When true, evaluates to true if the
Variableis a string, false otherwise. When false, the meaning is inverted. - IsTimestamp
-
Contains a boolean value. When true, evaluates to true if the
Variableis a string formatted as a timestamp, false otherwise. When false, the meaning is inverted. - NumericEquals
-
Contains a numeric value. Evaluates to true if the
Variablematches the value, false otherwise. - NumericEqualsPath
-
Contains a JSONPath to a value in the input. The value is used as in
NumericEquals. - NumericGreaterThan
-
Contains a numeric value. Evaluates to true if the
Variableis greater than the value, false otherwise. - NumericGreaterThanPath
-
Contains a JSONPath to a value in the input. The value is used as in
NumericGreaterThan. - NumericGreaterThanEquals
-
Contains a numeric value. Evaluates to true if the
Variableis greater than or equal to the value, false otherwise. - NumericGreaterThanEqualsPath
-
Contains a JSONPath to a value in the input. The value is used as in
NumericGreaterThanEquals. - NumericLessThan
-
Contains a numeric value. Evaluates to true if the
Variableis less than the value, false otherwise. - NumericLessThanPath
-
Contains a JSONPath to a value in the input. The value is used as in
NumericLessThan. - NumericLessThanEquals
-
Contains a numeric value. Evaluates to true if the
Variableis less than or equal to the value, false otherwise. - NumericLessThanEqualsPath
-
Contains a JSONPath to a value in the input. The value is used as in
NumericLessThanEquals. - StringEquals
-
Contains a string value. Evaluates to true if the
Variableis equal to the value, false otherwise. - StringEqualsPath
-
Contains a JSONPath to a value in the input. The value is used as in
StringEquals. - StringGreaterThan
-
Contains a string value. Evaluates to true if the
Variableis comes after the value lexicographically, false otherwise. - StringGreaterThanPath
-
Contains a JSONPath to a value in the input. The value is used as in
StringGreaterThan. - StringGreaterThanEquals
-
Contains a string value. Evaluates to true if the
Variableis equal to or comes after the value lexicographically, false otherwise. - StringGreaterThanEqualsPath
-
Contains a JSONPath to a value in the input. The value is used as in
StringGreaterThanEquals. - StringLessThan
-
Contains a string value. Evaluates to true if the
Variablecomes before the value lexicographically, false otherwise. - StringLessThanPath
-
Contains a JSONPath to a value in the input. The value is used as in
StringLessThan. - StringLessThanEquals
-
Contains a string value. Evaluates to true if the
Variableis equal to or comes before the value lexicographically, false otherwise. - StringLessThanEqualsPath
-
Contains a JSONPath to a value in the input. The value is used as in
StringLessThanEquals. - StringMatches
-
Contains a string value in the form of a pattern containing wildcards (
*). Evaluates to true if theVariablematches the pattern, false otherwise. - TimestampEquals
-
Contains a string value containing an RFC3331 timestamp. Evaluates to true if the
Variablematches the timestamp, false otherwise. - TimestampEqualsPath
-
Contains a JSONPath to a value in the input. The value is used as in
TimestampEquals. - TimestampGreaterThan
-
Contains a string value containing an RFC3331 timestamp. Evaluates to true if the
Variableis later than the timestamp, false otherwise. - TimestampGreaterThanPath
-
Contains a JSONPath to a value in the input. The value is used as in
TimestampGreaterThan. - TimestampGreaterThanEquals
-
Contains a string value containing an RFC3331 timestamp. Evaluates to true if the
Variableis equal to or later than the timestamp, false otherwise. - TimestampGreaterThanEqualsPath
-
Contains a JSONPath to a value in the input. The value is used as in
TimestampGreaterThanEquals. - TimestampLessThan
-
Contains a string value containing an RFC3331 timestamp. Evaluates to true if the
Variableis before than the timestamp, false otherwise. - TimestampLessThanPath
-
Contains a JSONPath to a value in the input. The value is used as in
TimestampLessThan. - TimestampLessThanEquals
-
Contains a string value containing an RFC3331 timestamp. Evaluates to true if the
Variableis equal to or earlier than the timestamp, false otherwise. - TimestampLessThanEqualsPath
-
Contains a JSONPath to a value in the input. The value is used as in
TimestampLessThanEquals.
Examples
{
"Type": "Choice",
"Choices": [
{
"Variable": "$.reader_choice",
"StringEqualsPath": "$.novel_definition_of_villany",
"Next": "VillanousEnding"
},
{
"And": [
{
"Variable": "$.is_star_wars_novel",
"BooleanEquals": true
},
{
"Variable": "$.reader_choice",
"StringEquals": "GoToTosheStation"
}
],
"Next": "GoodEnding"
},
{
"And": [
{
"Or": [
{
"Variable": "$.is_harry_potter_novel",
"BooleanEquals": true
},
{
"Variable": "$.has_arthurian_setting",
"BooleanEquals": true
}
]
},
{
"Variable": "$.reader_choice",
"StringEquals": "LearnMagic"
}
],
"Next": "GoodEnding"
}
],
"Default": "BadEnding"
}