validate.presence
returns a given value if the value is present or an error if the value is not present.
Function category: Validate​
validate.presence(arg1, arg2)
Arguments | Description |
| Datum or reference to a datum. |
| Error message to return if |
Let's say we receive the following data structure.
{"driver_ids":{"first": 999,"second": null}}
If we want to perform an operation but aren't sure whether the value exists, we can check if the first value exists using the following function.
# Confirm if a value exists.validate.presence(driver_ids.first,"This error message won't be executed")​# Returns 999## This value indicates the value exists
We can check the second value exists using the following function.
# Conformvalidate.presence(driver_ids.second,"Value was null!")​# Returns "Value was null!"## This value does not exist