Choice allows flows to take different paths inside a pipeline. It's part of a components set that helps with the integrations organization.
                         

To work with this type of component, you must know 2 structure types of Choice. They're used to create the paths: 

  • WHEN: defines a condition that allows the flow to take a different path towards a specific execution line. You must declare at least 1 condition. 
  • OTHERWISE: the structure is executed when none of the WHEN conditions is attended. You must declare at least 1 condition. 

          

Take a look the the configuration parameters of this component:

  • Label: defines the path name. It must be a unique name that can be repeated in the pipeline.
  • Type: defines the structure of the different path your flow should take (WHEN or OTHERWISE).
  • Type Rules: define the language type (SIMPLE or JSON PATH), which will be used for the condition declaration (every time WHEN gets chosen in the “Type” parameter).
  • Condition: declares the condition used to define if the path must be executed. When the previously defined conditions generate conflict or cause an overlap, only one of them will be executed (every time WHEN gets chosen in the “Type” parameter).

           

TYPE RULES

  • JSON PATH

Defines expressions that go through a JSON component to reach a subset. Whenever you use Choice, a match will be made for the path execution.
           

Imagine that, in the path that comes before Choice, your data flow has the following output:

{

"city" : "New York"

}

            

The following Condition declared as WHEN validates the path your flow should take:

$.[?(@.city == 'New York')]

         
           
Know the other options for the JSON PATH declaration:

  • $: the object root or array.
  • .property: selects a specific object in the related object.
  • ['property']: selects a specific property in the related object. Be sure to put only single quotes around the property name. Tip: consider this instruction if the property name has specific characters, such as spaces, or begins with a character other than A..Za..z_.
  • [n]: selects the n-th element of an array. The indexes start with 0.
  • [index1,index2,]: selects array elements with specific indexes and returns a list.
  • ..property: recursive descent: searches for a specific property name recursively and returns an array with all the values with this property name. It always returns a list even if only 1 property is found.
  • *: wildcard selects all the elements in an object or array, no matter that their names or indexes are. For example, address.* means all the properties of the address object and book[*] means all the items inside a book array.
  • [start:end] / [start:]: selects elements of a start array and even, although not necessarily, an end array. If the end is omitted, select all the arrays until the end of the array. A list is returned.
  • [:n]: selects the first n elements of the array. A list is returned.
  • [-n:]: selects the last n elements of the array. A list is returned.
  • [?(expression)]: filter expression. It selects all the elements in an object or array that match the specified filter. A list is returned.
  • [(expression)]: script expressions can be used instead of explicit property names or indexes. For example, [(@.length-1)], that selects the last item of an array. Here, the length refers to the current array length more than a JSON file named "length".
  • @: used for filter expressions to make reference to the current node that is being processed.
  • ==: equal to . 1 and '1' are considered the same result. String values must be attached in single quotes (and not in double quotes): [?(@.color=='red')].
  • !=: different than. String values must be attached in single quotes.
  • >: greater than.
  • >=: greater than or equal to.
  • <: less than.
  • <=: less than or equal to.
  • =~: compatible with a Java Script RegEx. For example, [?(@.description =~ /cat.*/i)] matches itens whose descriptions start with cat (case-insensitive). 
  • !: used to deny a filter. For example, [?(!@.isbn)] matches items that don't have the isbn property. 
  • &&: logical AND operator. Example:
[?(@.category=='fiction' && @.price < 10)]

     

  • ||: logical OR operator. Example:
[?(@.category=='fiction' || @.price < 10)]


   

To know more, click here.

               

SIMPLE

It's basically destined to be a small and simple language to evaluate Expressions and predicates without demanding new dependences or JSON PATH knowledge.
                  

Imagine that, in the path that comes before Choice, your data flow has the following output:

{

"city" : "New York"

}

                       
The Condition declared as WHEN validates the path your flow should take:

#{city} == 'New York'

         

Know the other options for the SIMPLE declaration:

  • ==: equal to.
  • =~: equal to, case-insensitive when comparing strings.
  • >: greater than.
  • >=: greater than or equal to.
  • <: less than.
  • !=: different.
  • !=~: different than, case-insensitive when comparting strings.
  • regex: validates if string matches the specified RegEx. Eg.: #{city} regex ‘New.*’ 
  • &&:  logical AND operator. Example:
#{city} == 'New York' && #{state} == 'NY'
  • ||: logical OR operator. Example:
#{city} == 'New York' || #{state} == 'CA'

                               

 Example:

Did this answer your question?