Not sure if I’ve termed it correctly, but how do I convert a string variable with json as the value to a actual iterable json object?
e.g. a straight json object works:
{% set json_object = {"room":"bedroom","lights":[{"light_name":"lamp1"},{"light_name":"lamp2"}]} %}
{% for light in json_object.lights %}
{{ light.light_name }}
{% endfor %}
but a varialbe doesn’t, I’ve tried various things like creatong another variable with the | tojson filter.
(notice the single quote before the value is declared)
{% set json_string = '{"room":"bedroom","lights":[{"light_name":"lamp1"},{"light_name":"lamp2"}]}' %}
{% for light in json_string.lights %}
{{ light.light_name }}
{% endfor %}
Any assistance is appreciated, for what I’m attempting I can’t get away from using a string variable.