Good afternoon guys, I'm having a hard time finding the solution to this simple problem, I hope someone can help me.
I have a recursive array automatically generated by the source code, I use this array as the system's menu tree, however, it goes through a permission system, and some submenus are excluded, leaving certain menus empty, follow the example in JSON:
{
    "1": {
        "id": 1,
        "idFather": null,
        "nome": "test 1",
        "sub": {
            "4": {
                "id": 4,
                "idFather": 1,
                "nome": "test 1.1",
                "sub": {}
            },
            "5": {
                "id": 5,
                "idFather": 1,
                "nome": "test 1.2",
                "sub": {
                    "7": {
                        "id": 7,
                        "idFather": 5,
                        "nome": "test 1.3.1",
                        "sub": {}
                    },
                    "8": {
                        "id": 8,
                        "idFather": 5,
                        "nome": "test 1.3.2",
                        "sub": {}
                    }
                }
            },
            "6": {
                "id": 6,
                "idFather": 1,
                "nome": "test 1.3"
            }
        }
    },
    "2": {
        "id": 2,
        "idFather": null,
        "nome": "test 2"
    },
    "3": {
        "id": 3,
        "idFather": null,
        "nome": "test 3",
        "sub": {
            "10": {
                "id": 10,
                "idFather": 3,
                "nome": "test 3.2"
            }
        }
    }
}
Within key 1 I have key 4 with no other items, and I have key 5 with two keys (7 and 8), however, these 2 keys also do not contain items, so I need to remove keys 4, 7, 8 and consequently, key 5 too, as it will be empty at the end of the removals! Note that key 6 inside key 1, key 10 inside key 3 and key 2 do not contain the "sub" element, so it must not be removed!
I am Brazilian, so my English may be a little rusty.
 
    