Creating simple JSON using recursion

Fabian (TreeFam's fearless leader) had another email request: how do I generate simple JSON by traversing a tree object? The end result needed to be a nested pseudo-object structure where each object has a 'name' field and, optionally, a 'children' field that holds a list of similar pseudo-objects. This is the input format for a rather attractive tree viewer widget that is explained here and that might be adopted for future releases of TreeFam.