diff --git a/source/_docs/configuration/templating.markdown b/source/_docs/configuration/templating.markdown index 3a481425f52..48f8ec087a8 100644 --- a/source/_docs/configuration/templating.markdown +++ b/source/_docs/configuration/templating.markdown @@ -903,6 +903,29 @@ The temperature is 25°C {% endraw %} +`from_json(default)` function will attempt to convert the input to `json`. If that fails, returns the `default` value, or if omitted raises an error. + +#### Template + +{% raw %} + +```text +{% set result = 'not json'|from_json('not json') %} +The value is {{ result }} +``` + +{% endraw %} + +#### Output + +{% raw %} + +```text +The value is not json +``` + +{% endraw %} + ### Is defined Sometimes a template should only return if a value or object is defined, if not, the supplied default value should be returned. This can be useful to validate a JSON payload.