Menu tree and referring to items inside items

In our current version of ignition (vision side) we have nice navigation system that refers to mysql table that has all king of attributes like depth, parentids and so on. This is linked to table to create navigation list.

Im trying to move this table to work with menu tree using python. I can get it working if in advance i know how many sub items there will be or i just limit to lets say depth of 5.
Referrals to items inside items that would allow more sub items would look something like this
self.props.items = jsonstring
self.props.items[0][“items”] = jsonstring
self.props.items[0][“items”][0][“items”] = jsonstring
self.props.items[0][“items”][0][“items”][0][“items”] = jsonstring
self.props.items[0][“items”][0][“items”][0][“items”][0][“items”] = jsonstring
self.props.items[0][“items”][0][“items”][0][“items”][0][“items”][0][“items”] = jsonstring

Where jsonstring is just another instance of
[{
“target”: “”,
“items”: [],
“navIcon”: {
“path”: “material/chevron_right”,
“color”: “”
},
“label”: {
“text”: “Menu Item 1”,
“icon”: {
“path”: “material/list”
}
},
“visible”: True,
“enabled”: True,
“showHeader”: True,
“style”: {
“classes”: “”
}
}]

So basicly im getting it to work with some loops etc. if i limit amount of subcategories. But in future if in future customer wants to add 6th subcategory it wouldnt work. Problem is this [0][“items”][0][“items”][0][“items”][0][“items”][0][“items”] that i cant get to work with my depth attribute without knowing how many there is at the start. Is there way to create it at the start when i can get maximum depth attribute inside python? Lets say i know at the start there will be 4 sublevels can i get python to create [0][“items”][0][“items”][0][“items”][0][“items”] referral without me specifying it at the start?

If you are using a relatively modern version of MySQL, you can use a recursive Common Table Expression to retrieve your data in the appropriate order for a tree, assuming you have some table column, parentId perhaps, that connects children to parent nodes.