def construct_node(tree, level, threshold = 1000): root=Node(tree['tagName']) if 'children' not in tree or level == threshold: root.label = tree['tagName'] return root for child in tree['children']: child_node = construct_node(child, level+1, threshold) root.addkid(child_node) return root