I have the following json data:
{"results":
{"xxxxxx":{"id":"as23","status":1,"res":"xsd"},
{"xxxxxx":{"id":"fds34","status":2,"res":"dox"},
{"xxxxxx":{"id":"as23","status":1,"res":"kog"},
{"xxxxxx":{"id":"dgs5","status":2,"res":"dox"},
{"xxxxxx":{"id":"as23","status":2,"res":"dox"},
{"xxxxxx":{"id":"as23","status":1,"res":"dox"}
The list is very long, but you get the idea. What I want, is to look up for every object containing the id as23
, and count how many of them have the status 1
.
So, I am using this in HomeAssistant as a rest sensor, and my filter expression looks like this:
{{ value_json.results|selectattr("id", "==", "as23")|selectattr("status", "eq", 1)|list|length }}
My issue is: I don't know what the value of xxxxxx
are, and they can differ, and still contain the id as23
.
How to achieve this?