I am trying to group an array of objects by year and Month

I have the following data:

Sample Data

{ “id”:
“831a2786-eb7f-49de-98b1-5ae838e870ae”, “label”: “testLabel”,
“description”:
“abcdefabcdef123abcdeabcdefabcdef123fabcdef123abcdcdefahtt”,
“identifier”: “test123”, “regularDays”: [
{
“dayId”: 1,
“openingTimes”: [
“00:00:00 – 00:30:00”,
“01:00:00 – 01:30:00”
]
} ], “specialDays”: {
“closeDays”: [
{
“month”: 12,
“year”: 2021,
“dateList”: [
20,
22,
23,
24,
25,
26
]
},
{
“month”: 1,
“year”: 2022,
“dateList”: [
1,
3,
4,
5,
6,
7
]
}
],
“openDays”: [
{
“month”: 12,
“year”: 2021,
“groups”: [
{
“dateList”: [
16,
17,
18,
19,
21,
27
],
“timeSlots”: [
“01:00:00 – 01:30:00”,
“00:00:00 – 00:30:00”
]
}
]
}
] } }

**expected result:**

 'specialDays' : {
                            '2011': { // Year 2011
                                '01': { // January
                                    'closeDay' : { 
                                        'dateList':[2,3,4,5,6]
                                    },
                                       'openDay' : { 
                                               'dateList':[2,3,4,5,6],
                                               "timeSlots": [
                                                        "01:00:00 - 01:30:00",
                                                         "00:00:00 - 00:30:00"
                                                           ]
                                                        }
                                                  },
                                '02' : { // February
                                    'closeDay' : { 
                                         'dateList':[2,3,4,5,6]
                                    },
                                    'openDay' : {
                                         'dateList':[2,3,4,5,6],
                                           "timeSlots": [
                                                     "01:00:00 - 01:30:00",
                                                      "00:00:00 - 00:30:00"
                                                    ]
                                    }
                                }
                            },
                            '2012' : { // Year 2012
                                '01' : { // January
                                    'closeDay': { 
                                       'dateList':[2,3,4,5,6]
                                    }
                                },
                                '03': { // March
                                     'closeDay': {
                                       'dateList':[2,3,4,5,6]
                                     },

                                     'openDay' : {
                                      'dateList':[2,3,4,5,6],
                                        "timeSlots": [
                                                  "01:00:00 - 01:30:00",
                                                   "00:00:00 - 00:30:00"
                                                 ]
                                 }
                                }
                        }
                      }