How to categorize by a certain attribute and show all values of that specific attribute in a refinementList?

I have a collection with objects that all have a nested array called attributes with varying sizes, some might have 10 attributes and others 5 and so forth… An object might look something like this:

{ 
id: 141,
name: "Peter Parker",
attributes: [
{type: "Hair", value: "Brown"},
{type: "Shoes", value: "Red"},
...
]}

So what I want is a facet for each attribute and in each of those facets I’d like to display all the values that are in the collection together with the count/occurrence of that value in the collection (much like a refinementList). But I can’t wrap my head around how to solve this… Please can someone guide me? :slight_smile: Thanks!