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​
validate.not-empty(arg1, arg2)
Argument | Description |
| Datum or a reference to a datum. |
| Error message to return if |
Let's say we were given 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 check if the value is empty using this function.
# Confirm if the first value is emptyvalidate.not-empty(driver_ids.first, "This error message won't be executed")​# Returns 999## This indicates the value is not 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.
# Confirm if the second value is emptyvalidate.not-empty(driver_ids.second, "Value was empty!")​# Returns "Value was empty!"## This indicates the second value is empty