Grouping Duplicate key values of an array and displaying the count in N1QL

{
"brands": [
  {
    "value": "brand1"
  },
  {
    "value": "brand1"
  },
  {
    "value": "brand2"
  }
],
"count": 3,
"name": "Windows"
}

I have an document like this in that , How can I group the array contents with the similar value and get the count of it ? Something like below . Can someone help me with this ?

{
"brands": [
{
  "value": "brand1",
  "count": 2
},
{
  "value": "brand2",
  "count":1
}
],
"count": 3,
"name": "Windows"
}
SELECT d.*,  brands, ARRAY_SUM(brands[*].`count`) AS count
FROM default AS d
LET brands =  (SELECT b.`value`, COUNT(1) AS count
               FROM d.brands AS b
               GROUP BY b.`value`)
WHERE ....