Problems getting correct rest value

Hi, I am trying to parse this with a rest sensor and get the value of “statusSeverityDescription” as sensor value. I can’t seem to get it to work. The live api is available here: https://api.tfl.gov.uk/Line/tram/Status

[{"$type":"Tfl.Api.Presentation.Entities.Line, Tfl.Api.Presentation.Entities","id":"tram","name":"Tram","modeName":"tram","disruptions":[],"created":"2022-01-18T15:07:11.55Z","modified":"2022-01-18T15:07:11.55Z","lineStatuses":[{"$type":"Tfl.Api.Presentation.Entities.LineStatus, Tfl.Api.Presentation.Entities","id":0,"statusSeverity":10,"statusSeverityDescription":"Good Service","created":"0001-01-01T00:00:00","validityPeriods":[]}],"routeSections":[],"serviceTypes":[{"$type":"Tfl.Api.Presentation.Entities.LineServiceTypeInfo, Tfl.Api.Presentation.Entities","name":"Regular","uri":"/Line/Route?ids=Tram&serviceTypes=Regular"}],"crowding":{"$type":"Tfl.Api.Presentation.Entities.Crowding, Tfl.Api.Presentation.Entities"}}]

I have tried with this:

  - platform: rest
    name: tram_status
    resource: https://api.tfl.gov.uk/Line/tram/Status
    value_template: "{{ value_json.x[0].lineStatuses[0].statusSeverityDescription }}"
    scan_interval: 15

I do mapping like this:
value_json[1]['key1'][0]['key2']

I would help you with yours but digging through unformatted JSON is not on my ToDo list for today :wink:

value_template: "{{ value_json[0].lineStatuses[0].statusSeverityDescription }}"

Firefox does a nice visual representation of JSON data received from URL given:

No Firefox.
I had a Notepad++ addon for that at some point. Probably need to find that one again.

Thank you all!

1 Like