I just put together two new functions that should help with this use-case.
objectKeys(object)
- outputs an array which contains the key names of the top-level properties of the input objectobjectValues(object)
- outputs an array which contains the values of the top-level properties of the input object
obj = { "first": "value1", "second": 2, "third": {"foo": "bar"}}
objectKeys(obj) #\\ Output: ["first", "second", "third"]
objectValues(obj) #\\ Output: ["value1", 2, {"foo": "bar"}]
If you need the key and the value, you can get the object keys and use map to iterate through them while referencing the original object
obj = {
"first": { "name": "John" }
"second": { "name": "Mark" }
"third": { "name": "Olivia" }
}
map(objectKeys(obj), concat("The name of the ", x , " person is ", obj[x].name))
Output:
["The name of the first person is John","The name of the second person is Mark","The name of the third person is Olivia"]
In your case, if you only wanted the ‘symbol’ property within the nested object, you could use objectValues
to iterate directly through the values, ignoring the top-level keys.
response = $context.response.data
stockSymbols = map(objectValues(response), x.symbol)
join(stockSymbols, "\r\n")