I found a workaround solution myself. I will left this here in case someone had had the same problem:
If you need to make a webservice function that returns and array with multiple, undefined levels:
In my webservice plugin at the main method public static function get_tree($rootid), after I build my tree, I don't return it, I simply print it:
And in my method public static function get_tree_returns(), I just return null.
It works like a charm, however be aware of this small issues:
- The Moodle webservice documentation relies on the existence of the _returns() method. Returning null causes the method entry in documentation not show the returning values.
- The moodlewsrestformat is ignored for this method. The returning format will be always json in this case.