Optional JSON values from MQTT

Hi,

I have an MQTT device, it provides a error description if it is in an error state. I used a Value template to extract the information:
{{ value_json.error }}

If no error is present, the value is not part of the MQTT message.
So my question: How to test if a “error” value is present and to provide a default value (e.g., no_error) if the value is absent. (At the moment the UI gives me thee string “error” if no error is present.)

Thanks

{{ value_json.error if 'error' in value_json else '' }}

Read as: if the key named error exists in the dictionary named value_json. Use None if you don’t want an empty string.

If you also want to set an availability template:

{{ 'error' in value_json }}
{{ value_json.error | default(none) }}

Optionally replace none with whatever you want it to report when the error key doesn’t exist (such as "no value" or 0 or "" or whatever best fits your application).

My solution is:
{{ value_json.error | default('no_error') }}

Thanks! (The equating was missing.)
The documentation link is very useful. I read the Jason parsing documentation, so I missed the default value part.