$ifNull

$ifNull operator checks if the condition resolves to null (or None) and returns you the item based on the condition passed in the object. You can use this in any Expression Object.

Syntax

{
    "$ifNull": [ <expr>, <true_val>, <default> ]
}

Properties

FieldDescriptionRequired

<expr>

The <expr> expression can be any valid expression object.

It can also be a Magical Autocomplete.

true

<true_val>

The value to return if the <expr> is found to be null (or None). It can also be a Magical Autocomplete.

true

<default>

The value to return if the <expr> is not found to be null (or None) It can also be a Magical Autocomplete.

true

Returns

<object> - Returns either the <true_val> or <default> based on the expr. 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 a null value currently.

{
    "$ifNull": [ 
        "$.variables.country",
        "US",
        "India"
    ]
}

The above expression returns US as the expr resolves to null.

Last updated