Just my opinion, it would be good to have a set max depth. Makes looping over it easier.
Also see https://gist.github.com/jimgwhit/cbbe5bb0d2556fdc7e37a86d3630239c
Concerning looping. Without a known max depth it just makes it harder, though there are flatten routines you can modify for this as needed.
During the flatten you could store the depth.
Also, and just me, looping over arrays is easier.
Edit
When I have Iterating to do, I just work it out normally with some practice and trial and error.