$cond

$cond operator lets you build conditions directly in CQL and returns you the item based on the condition passed in the object. You can use this in any Expression Object.

Syntax

{
    "$cond": [ <condition>, <true_val>, <false_val> ]
}

Properties

FieldDescriptionRequired

<condition>

The <condition> can be any valid condition object as long as it resolves to a boolean object.

It can also be a Magical Autocomplete.

true

<true_val>

The value to return if the <condition> resolves to true. It can also be a Magical Autocomplete.

true

<false_val>

The value to return if the <condition> resolves to false. It can also be a Magical Autocomplete.

true

Returns

<object> - Returns either the <true_val> or <false_val> based on the condition. The object type can be anything based on the values provided.

Examples

With Magical Autocomplete

Let's say we have declared a variable country in our API flow, which has an array value of US currently.

{
    "$cond": [ 
        { "$eq": ["$.variables.country", "India"] },
        10,
        20
    ]
}

The above expression returns 20 as the condition becomes false.

Last updated