validate.not-empty

validate.not-empty returns a given value if the value is not empty. If the the value is empty, an error is returned. Collections with no elements, including empty strings, are considered empty.

Function category: Validate

Syntax

validate.not-empty(arg1, arg2)

Argument

Description

arg1

Datum or a reference to a datum.

arg2

Error message to return if arg1 evaluates to null.

Example

Example 1: Determine if a value is empty

If we receive the following data structure:

{
"driver_ids":
{
"first": 999,
"second": ""
}
}

If we want to perform an operation but aren't sure whether the value will is empty or not empty, we can confirm that it isn't (or is) with validate.not-empty:

validate.not-empty(driver_ids.first, "This error message won't be executed")

This returns the following, which indicates the value is not empty:

999

Example 2: Determine if another value is empty

Using the same response and an error message, we can determine if another value is empty. If it is not empty, then the string is returned. If it is empty, then the error message is returned.

validate.not-empty(driver_ids.second, "Value was empty!")

This returns the following:

"Value was empty!"