I have an array of objects and I want to remove some duplicates in this array, I want to keep the count of the duplicates though.
My input is:
[
{
"foo": 1,
"bar": "a",
"baz": "whatever"
},
{
"foo": 1,
"bar": "a",
"baz": "hello"
},
{
"foo": 1,
"bar": "b",
"baz": "world"
}
]
(not sure if it's important but the uniqueness of an object is based on foo
and bar
, not baz
.
An example of desired output would then be:
[
{
"foo": 1,
"bar": "a",
"baz": "whatever",
"count": 2
},
{
"foo": 1,
"bar": "b",
"baz": "world",
"count": 1
}
]
or even:
[
{
"count": 2,
"data": {
"foo": 1,
"bar": "a",
"baz": "whatever"
}
},
...
]
I know how to do the uniqueness part (with unique_by([.foo, .bar])
) but not the counting part.