Make JSON load order sane (explicit BFS).

The previous way of searching for JSON files was an unholy mix of stacks
and things that were acting more as a pre-order DFS, which made it hard
to express the correct JSON loading order.

Made into a BFS, so that depth (distance from root) will be the only
determinant of load order, as the intention seemed to be.