I have a parent-child connection database. The data is as follows, but may be presented depending on what you want (dictionaries, list of lists, JSON, etc.).
links=(("Tom","Dick"),("Dick","Harry"),("Tom","Larry"),("Bob","Leroy"),("Bob","Earl"))
The result I need is a hierarchical JSON tree that will be displayed using d3. There are discrete subtrees in the data that I will attach to the root of the node. Therefore, I need to follow the links recursively and build a tree structure. The most I can get is to iterate over all the people and add my children, but I cannot figure out how to use higher order links (for example, how to add a person with children to someone else's child). This seems like another question here , but I cannot know the root nodes in advance, so I cannot implement the decision made.
I am going to use the following tree structure from my example data.
{ "name":"Root", "children":[ { "name":"Tom", "children":[ { "name":"Dick", "children":[ {"name":"Harry"} ] }, { "name":"Larry"} ] }, { "name":"Bob", "children":[ { "name":"Leroy" }, { "name":"Earl" } ] } ] }
This structure looks like this in my d3 layout. 
Andrew Barr
source share