To explain my issue further. Have been playing inside the template editor. Test code below. This code tests if JSON item has value None, if not add it to the list ns.value_list.
{% set value_json = {
"display_name": "whateverroadname 10",
"address": {
"road": "whateverroadname",
"house_number": "10",
"test": "None"
}
} %}
{% if not value_json.display_name == "Unknown" %}
{% set ns=namespace(value_list=[]) %}
{% for key, value in value_json.address | items %}
{% if value != 'None' %}
{% set ns.value_list = ns.value_list ~ value %}
{% endif %}
{% endfor %}
{{ ns.value_list }}
{% else %}
{{ "Unknown location..." }}
{% endif %}
This results in: []whateverroadname10 while I am expecting whateverroadname 10.
In addition, {{ ns.value_list | join(',') }} results in: [,],w,h,a,t,e,v,e,r,r,o,a,d,n,a,m,e,1,0 instead of whateverroadname,10
According to the jinja documentation, list() is supposed to return a list of characters. However, it does not explain [] ate the beginning of my result.
My main question is:
How do I iterate through a JSON response, and build a string based on items that do not have the value None which would result in whateverroadname, 10
Many thanks in advance for any pointers or assistance!