Lookup | LOOKUP

Syntax

LOOKUP( [input], [key], [default = null] )

Parameters

input
Any data may be used as the input, but should probably be an ARRAY or MAP for this operation to be useful.

key
A path to retrieve from the INPUT. For more information on the path syntax used by instalink.io see the dedicated documentation on that subject.

default optional
A default value to return if the value is not found.

Return Value

The value at the PATH within the INPUT. If a value is not found, the DEFAULT value is returned.

Description

Retrieve a value at a path within another value.

Examples

LOOKUP(null, 'a.b.c') # returns NULL
LOOKUP(null, 'a.b.c', 24) # returns 24
# VALUE is [
#   "a" => [
#     "b" => [
#       "c" => "puppies"
#     ]
#   ]
# ]
LOOKUP(VALUE, "a.b.c") # returns "puppies"
# VALUE is [
#   "a" => [
#     "b" => [
#       "c" => "puppies"
#     ]
#   ]
# ]
LOOKUP(VALUE, "a.b.d") # returns NULL
Indexing can be used to search multiple paths, in which case an ARRAY of results is returned.
# VALUE is [
#   "people" => [
#     ["id" => 1, "name" => "Amy"],
#     ["id" => 2, "name" => "Barry"],
#     ["id" => 3, "name" => "Cindy"]
#   ]
# ]
LOOKUP(VALUE, "people[].name")
# returns [
#   "Amy", "Barry", "Cindy"
# ]
Indexing can alse be used to search multiple paths of MAPS / OBJECTS.
# VALUE is [
#   "people" => [
#     "1" => ["id" => 1, "name" => "Amy"],
#     "2" => ["id" => 2, "name" => "Barry"],
#     "3" => ["id" => 3, "name" => "Cindy"]
#   ]
# ]
LOOKUP(VALUE, "people[].name")
# returns [
#   "Amy", "Barry", "Cindy"
# ]
Multiple levels of indexing are possible.
# VALUE is [
#   "people" => [
#     [
#       "id" => 1, 
#       "name" => "Amy", 
#       "pets" => [
#         ["name" => "Arthur", "species" => "dog"]
#         ["name" => "Aaron" , "species" => "iguana"]
#       ]
#     ],
#     [
#        "id" => 2, 
#        "name" => "Barry",
#        "pets" => [
#           ["name" => "Betty", "species" => "cat"]
#         ]
#     ],
#   ]
# ]
LOOKUP(VALUE, "people[].pets[].species")
# returns [
#   ["dog", "iguana"],
#   ["cat"]
# ]