I am trying to transform this object :
[
    {
        "keyword":"apple",
        "category_1":"object",
        "category_2":"living",
        "category_3":"fruit",
        "count":5
    },
    {
        "keyword":"orange",
        "category_1":"object",
        "category_2":"living",
        "category_3":"fruit",
        "count":1
    },
    {
        "keyword":"table",
        "category_1":"object",
        "category_2":"non living",
        "category_3":"house item",
        "count":3
    },
    {
        "keyword":"cat",
        "category_1":"object",
        "category_2":"living",
        "category_3":"animal",
        "count":4
    },
    {
        "keyword":"stadium",
        "category_1":"place",
        "category_2":"sport related",
        "category_3":"indoor",
        "count":2
    }
]
into an object like this :
[
    {
        label: 'object',
        count: 9,
        childs: [
            {
                label: 'living',
                count: 6,
                childs: [
                    {
                        label: 'fruit',
                        count: 6,
                        childs: [
                            {
                                keyword: 'apple',
                                count: 5,
                            },
                            {
                                keyword: 'orange',
                                count: 1,
                            }
                        ]
                    }
                ]
            },
            {
                label: 'non living',
                count: 3,
                childs: [
                    {
                        label: 'animal',
                        count: 3,
                        childs: [
                            {
                                keyword: 'cat',
                                count: 3,
                            }
                        ]
                    }
                ]
            }
        ]
    },
    {
        label: 'place',
        count: 2,
        childs: [
            {
                label: 'sport related',
                count: 2,
                childs: [
                    {
                        label: 'indoor',
                        count: 2,
                        childs: [
                            {
                                keyword: 'stadium',
                                count: 2,
                            }
                        ]
                    }
                ]
            }
        ]
    }
]
I tried with Array.reduce in a recursive manner, but I have troubles with recursivity, I always end up hitting a wall. As you can see, the point is to turn the array into a nested object grouping its elements by category (the count part is not essential)
If anyone has any hindsight on this
childreninstead ofchilds?