GetValueJSON
Extracts the value of a specified key from a JSON object. If the key exists in the object, the associated value is returned.
GetValueJSON(
obj: str,
key: str
)
Where:
- obj: An array in the format '[{"first_name": "Brad", "last_name": "Pitt"}]' for example.
- key: A string or list of strings representing a numerical value indicating the position of an element in an array.
Example
The example below searches within the JSON object for the specified key and displays the result in the Sandbox chat.
{{set(
name="MyArray",
value=AppendItemsArrayJSON(
array="[]",
items=[
'{
"first_name": "Brad",
"last_name": "Pitt"
}',
'{
"first_name": "Matt",
"last_name": "Damon"
}',
'{
"first_name": "Leonardo",
"last_name": "DiCaprio"
}',
'{
"first_name": "Robert",
"last_name": "De Niro"
}'
]
)
)}}
{{SendMessage(message=MyArray)}}
{{set(
name="LastName",
value=GetValueJSON(
obj='
{
"first_name": "Leonardo",
"last_name": "DiCaprio"
}',
key="last_name"
)
)}}
{{SendMessage(message=LastName)}}
[{"first_name":"Brad","last_name":"Pitt"},{"first_name":"Matt","last_name":"Damon"},{"first_name":"Leonardo","last_name":"DiCaprio"},{"first_name":"Robert","last_name":"De Niro"}]
"DiCaprio"
Updated 7 months ago