I have some json input that comes as a list of objects (not as a json array) like, for which I want to count the number of active, and the number of inactive:
{
"key" : "state",
"value" : "active"
}
{
"key" : "state",
"value" : "active"
}
{
"key" : "state",
"value" : "active"
}
{
"key" : "state",
"value" : "inactive"
}
I want to transform using only JQ (in fact it will be handled by jackson-jq in java code, so I can not use some shell tricks).
I tried many things, like select(.value == "active") | length to get the number of active, but it is always handle object per object.
Even when using reduce, it is always handled object per object.
Example of output is :
2
2
2
(I have 3 objects with 2 fields that match value="active)
The output that I expect is :
3
Here is a playground with my example.