Extract JSON Value template

Hello,
I’m getting stuck and confused trying to extract some JSON values from a rest sensor. Help would be very much appriciated.
I would like to extract from below the two “items” from the value_json and write each attribute like name, status translated, delay, etc. into a sensor.

{## Imitate available json data: ##}
{% set value_json = {
  "items": [
    {
      "name": "WAN_GW",
      "address": "fe66::77a9:c4aa:fed2:b234",
      "status": "none",
      "status_translated": "Online",
      "loss": "~",
      "stddev": "~",
      "delay": "~"
    },
    {
      "name": "WAN_PPPOE",
      "address": "92.111.33.244",
      "status": "none",
      "loss": "0.0 %",
      "delay": "5.7 ms",
      "stddev": "0.2 ms",
      "status_translated": "Online"
    }
  ],
  "status": "ok"
} %}

{## Extraxt json date into sensors: ##}
{{ value_json }}
{{ value_json.status }} 
{{ value_json["items"]["name"][WAN_PPPOE]["stddev"] }}

Solved it. Got confused as I thought this is an array.

{## Extraxt json date into sensors: ##}
{{ value_json }}
{{ value_json.status }} 
{{ value_json["items"] }} 
{% for item in value_json["items"] %}
    <li>{{ item.name|e }}</li>
    <li>{{ item.status_translated|e }}</li>
    <li>{{ item.address|e }}</li>
    <li>{{ item.loss|e }}</li>
    <li>{{ item.delay|e }}</li>
    <li>{{ item.stddev|e }}</li>
{% else %}
    <li><em>no item found</em></li>
{% endfor %}
1 Like