Performs a safe lookup on a map, returning null
if the key is not found.
For nested maps, a list of keys can be used to drill down into the map, using
a nested key lookup. For example, map.get(my2DMap, ["key1", "key2"])
is
equivalent to map.get(map.get(my2DMap, "key1"), "key2")
.
You can use the conditional function
default
with map.get
to safely access optional values in a map. For an example, see
Read map values.
Arguments
Arguments | |
---|---|
map |
The map to perform the lookup on. |
keys |
A string or list of strings used for the lookup. If a list is used, the function is called repeatedly, using the list of keys. |
Returns
If keys
is a single string, returns the indexed value. If the input is not
a map or if the map does not contain the key, returns null.
If keys
is a list, then a nested key lookup is performed and the value is
returned. If any of the nested objects are not maps or if the key does not
exist in the map then null
is returned.
Raised exceptions
Exceptions | |
---|---|
TypeError |
If the key is not a string or a list of strings. |
Examples
# Retrieve item for specified key from map # Returns "world" - init: assign: - my_map: {"key1": "hello", "key2": "world"} - returnStep: return: ${map.get(my_map, "key2")}