valueof()
Returns the value at the location corresponding to a specific key or index in the array or composite object specified as a parameter
Syntax
valueof(COMPOUND_OBJ_EXPR, KEY_EXPR)
Required Parameter
COMPOUND_OBJ_EXPR
- Expression that returns a composite object such as an associative array or an array
KEY_EXPR
- Expression that points to a value at a specific location, such as a key string in an associative array or the index number of an array
Description
This function returns a value corresponding to a specific key in the associative array or the array. It returns null
for the following exceptions:
- When you provide an object other than an associative array or an array in a composite object expression
- When the key of the associative array and the type of the key expression do not match
- When the index number of the array and the type of key expression do not match
Usage
-
Extract the item number 2 from an array with three elements (the index number in the array starts from
0
).json "{}" | eval foods=array("Apple","Banana","Cucumber") | eval food=valueof(foods,2) => "Cucumber"
-
Extract an item with the key
b
from a map object.json "{}" | eval foods=dict("a","Apple","b","Banana","c","Cucumber" ) | eval food = valueof(foods,"b") => "Banana"