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 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 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,
true
orfalse
, to which theVariable
is 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
Variable
istrue
orfalse
, 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
Variable
isnull
, 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
Variable
is 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
Variable
points 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
Variable
is a string, false otherwise. When false, the meaning is inverted. - IsTimestamp
-
Contains a boolean value. When true, evaluates to true if the
Variable
is a string formatted as a timestamp, false otherwise. When false, the meaning is inverted. - NumericEquals
-
Contains a numeric value. Evaluates to true if the
Variable
matches 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
Variable
is 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
Variable
is 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
Variable
is 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
Variable
is 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
Variable
is 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
Variable
is 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
Variable
is 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
Variable
comes 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
Variable
is 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 theVariable
matches the pattern, false otherwise. - TimestampEquals
-
Contains a string value containing an RFC3331 timestamp. Evaluates to true if the
Variable
matches 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
Variable
is 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
Variable
is 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
Variable
is 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
Variable
is 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"
}