Conditional Functions
Know what the conditional functions associated with the Double Braces are and how to use them.
The functions were created to:
- speed up the creation of your integrations even more
- decrease the complexity of your pipelines
- simplify data conversions and transformations during the flow of your pipelines
The conditional functions return a value according to the criteria you establish and are available for components that support Double Braces expressions. To know how to provide information to the components using this resource, click here.
By using Double Braces, you can combine the function with the access to the input JSON element of a component.
The function compares two objects (that can be numbers, strings, arrays, etc.) and verifies if they're the same.
EQUALTO(obj1, obj2 )
Let's say you need to validate if this object
{
"body1":{
"zip code": “72716”
}
}
is the same as this one:
{
"body2":{
"zip code": “73736”
}
}
In the example below the
false
value will be returned, because the objects are different:{
"valid": {{ EQUALTO( message.body1, message.body2 ) }}
}
The return of this function will be
true
or false
.By using Double Braces, you can combine the function with the access to the input JSON element of a component.
The function compares if the first number is greater than the second.
GREATERTHAN(num1, num2 )
{
"num1": 1,
"num2": 2
}
In the example below the "false" value will be returned:
{
"valid": {{ GREATERTHAN( message.num1, message.num2 ) }}
}
The
null
value is considered as the smallest possible value for comparison.GREATERTHAN(null, null)
will return false
.The return of this function will be
true
or false
.By using Double Braces, you can combine the function with the access to the input JSON element of a component.
The function compares if the first number is greater than or equal to the second.
GREATERTHANEQUAL(num1, num2)
{
"num1": 1,
"num2": 2
}
In the example below the
false
value will be returned:{
"valid": {{ GREATERTHANEQUAL( message.num1, message.num2 ) }}
}
The null value is considered as the smallest possible value for comparison.
GREATERTHANEQUAL(null, null)
will return true
.The return of this function will be
true
or false
.By using Double Braces, you can combine the function with the access to the input JSON element of a component.
The function allows you to make logical comparisons between a value and what you wait for.
Therefore, an IF instruction can have 2 results. The first result happens when the comparison is true and the second when it's false.
IF(comparison, value-if-true, value-if-false)
Let's say you need to make decisions depending if the received value is
true
or false
:{
"boolean": false
}
In the example below the condition value (value-if-false) will be assigned to JSON:
{
"zip code": {{ IF( message.boolean, "zip-code-ok", "zip-code-not-ok" ) }}
}
The return of this function will be any value provided in the messages of the
true
/false
conditional.By using Double Braces, you can combine the function with the access to the input JSON element of a component.
The function compares if the first number is smaller than the second.
LESSTHAN(num1, num2)
{
"num1": 1,
"num2": 2
}
In the example below the
true
value will be returned:{
"valid": {{ LESSTHAN( message.num1, message.num2 ) }}
}
The
null
value is considered as the smallest possible value for comparison.LESSTHAN(null, null)
will return false
.The return of this function will be
true
or false
.By using Double Braces, you can combine the function with the access to the input JSON element of a component.
The function compares if the first number is smaller than or equal to the second.
LESSTHANEQUAL(num1, num2)
{
"num1": 1,
"num2": 2
}
In the example below the "true" value will be returned:
{
"valid": {{ LESSTHANEQUAL( message.num1, message.num2 ) }}
}
The
null
value is considered as the smallest possible value for comparison.LESSTHANEQUAL(null, null)
will return true
.The return of this function will be "true" or "false".
By using Double Braces, you can combine the function with the access to the input JSON element of a component.
The function allows you to verify if the provided argument is an object.
ISOBJECT(object)
Let's say you need to verify if the received argument is an object:
{
"argument": false
}
Validating the argument:
{
"isObject": {{ ISOBJECT( message.argument) }}
}
The response will be
false
, because the value isn't an object.Now passing an object to the function:
{
"argument": {
"test": "xpto"
}
}
Validating the argument:
{
"isObject": {{ ISOBJECT( message.argument) }}
}
The response will be
true
.By using Double Braces, you can combine the function with the access to the input JSON element of a component.
The function allows you to verify if the provided argument is an array.
ISARRAY(object)
Let's say you need to verify if the received argument is an array:
{
"argument": false
}
Validating the argument:
{
"isObject": {{ ISARRAY( message.argument) }}
}
The response will be
false
, because the value isn't an array.Now passing an object to the function:
{
"argument": [{
"test": "xpto"
}]
}
Validating the argument:
{
"isArray": {{ ISARRAY( message.argument) }}
}
The response will be
true
.By using Double Braces, you can combine the function with the access to the input JSON element of a component.
The function allows you to verify if the provided argument is a boolean value.
ISBOOLEAN(objeto)
Let's say you need to verify if the received argument is a boolean value:
{
"argument": false
}
Validating the argument:
{
"isObject": {{ ISBOOLEAN( message.argument) }}
}
The response will be "true", because the value is boolean.
Now passing an object to the function:
{
"argument": {
"test": "xpto"
}
}
Validating the argument:
{
"isBoolean": {{ ISBOOLEAN( message.argument) }}
}
The response will be “false”.
By using Double Braces, you can combine the function with the access to the input JSON element of a component.
The function allows you to verify if the provided argument is a string.
ISSTRING(object)
Let's say you need to verify if the received argument is a string:
{
"argument": "test"
}
Validating the argument:
{
"isString": {{ ISSTRING( message.argument) }}
}
The response will be
true
, because the value is a string.By using Double Braces, you can combine the function with the access to the input JSON element of a component.
The function allows you to verify if the provided argument is a number.
ISNUMBER(object)
Let's say you need to verify if the received argument is a number:
{
"argument": 123
}
Validating the argument:
{
"isNumber": {{ ISNUMBER( message.argument) }}
}
The response will be "true", because the value is a number.
By using Double Braces, you can combine the function with the access to the input JSON element of a component.
The function allows you to verify if the provided argument is
null
.ISNULL(object)
Let's say you need to verify if the received argument is a null value:
{
"argument": null
}
Validating the argument:
{
"isNull": {{ ISNULL( message.argument) }}
}
The response will be
true
, because the value is a null value.By using Double Braces, you can combine the function with the access to the input JSON element of a component.
The function allows you to provide multiple comparisons and the due parameters that must be returned if one of these validations returns
true
. If no validation returns true
, the defined pattern will be used.SWITCHCASE(defaultValue, condition1, result1, condition2, result2, …., conditionN, resultN)
Let's say you need to validate some conditions to make a decision:
{
"argument": null
}
Validating the argument:
{
"result": {{ SWITCHCASE("failed", ISNULL(message.argument), "ok", ISNUMBER(message.argument), "nok" ) }}
}
Therefore, the function configuration will be:
Valor default: "failed"
Condition 1: ISNULL(message.argument)
Result If Condition 1 Matches: "ok"
Condition 2: ISNUMBER(message.argument)
Result If Condition 2 Matches: "nok"
The response will be "ok", because the first condition was met.
You can also read about these functions:
Last modified 2mo ago