Rewrite Links Array to include Nesting
In my experience, the structure you're looking for is created by the template layer. I would not recommend changing the link array directly. A good example template is core's stable theme's menu.html.twig. It uses a recursive twig macro to create nested lists.