I’m usually able to find examples that get me to a solution, but this one is frustrating me. I currently have Version 3.2.0.M1 running on an RPi3.
I have a channel returning a string of the form:
{ "items": [
{ "name": "A", "status": "OK" , "num": 2, ... },
{ "name": "B", "status": "OK" , "num": 0, ... },
{ "name": "C", "status": "NotOK", "num": 3, ... },
... ] }
I was able to use a JSONPATH Profile on a channel Item to get a sum of the num
fields:
$.sum($..num)
What I can’t figure out is a Profile to count the number of “NotOK” occurrences. I was hoping it would be as simple as
$.count($..status[?(@ == 'NotOK')])
but, I gather, only max
, min
, and sum
, but not count
, are supported.
I also tried playing with a REGEX but that’s even more obscure to me. And I was trying to avoid the complexity of an external Javascript file. Although I’d consider that if there was a way to pass it both the Channel JSON and the status value I want to count because there are several possible values in my case, each of which I’d like to separately count.
In similar manner, I was looking to avoid the complexity of a trigger firing to do the counting. After all, if the sum
can be done so simply and transparently, I assume(/hope) there’s a way to count in similar fashion?