Json attributes - [0]

I have I json file looking like

[ {"temperature": 77, "id": "sensor02", "name": "livingroom", "connected": true} ]

Because of the square brackets I use this to get the “connected” state:

in sensors.yaml

- platform: rest
  scan_interval: 10
  resource: someresource
  value_template: '{{ value_json[0].connected }}'
  json_attributes: 
    name: '{{ value_json[0].name }}'  
    #- value_json[0].name

this works for the connected state, but I don’t know how to setup the attributes. Both lines in the example above did not work.

The json_attributes only works for ‘top level’ json attributes - you can’t pick out an element within a structure. I haven’t tried with arrays, so I’m not even sure if it will work with arrays as the top level element.

ok thanks!

I haven’t tried with arrays, so I’m not even sure if it will work with arrays as the top level element.

I can confirm that it works at the top level so this works:

value_template: '{{ value_json[0].connected }}'