Skip to main content
Version: V2 (Ignition 8.1)

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

ParameterTypeNullableDescription
jsonDictFalseThe dictionary / JSON object to read from.
keyStringFalseThe key to look up.
defaultValueObjectTrueValue 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)