tamaki.mes.utils.getJsonElement
Description
Safely reads key from a dictionary (or JSON object). Returns the value for key if present;
otherwise returns defaultValue. If the lookup raises any error, defaultValue is returned instead
of propagating the exception.
Syntax
tamaki.mes.utils.getJsonElement(json, key, defaultValue="")
Parameters
| Parameter | Type | Nullable | Description |
|---|---|---|---|
json | Dict | False | The dictionary / JSON object to read from. |
key | String | False | The key to look up. |
defaultValue | Object | True | Value returned if the key is missing or the lookup fails. Defaults to an empty string "". |
Returns
The value stored at key, or defaultValue if the key is absent or the lookup fails.
Code Examples
# In a binding script transform: safely read a key, defaulting to False when absent
return tamaki.mes.utils.getJsonElement(value, "required", False)