We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`json_graph.tree_data` can cause maximum recursion depth error.
<!-- If you have a general question about NetworkX, please use the discussions tab to create a new discussion -->

<!--- Provide a general summary of the issue in the Title above -->

### Current Behavior
<!--- Tell us what happens instead of the expected behavior -->
Currently the algorithm compares the `n_nodes` with `n_edges` to check if `G` is a tree. https://github.com/networkx/networkx/blob/0cc70051fa0a979b1f1eab4af5b6587a6ebf8334/networkx/readwrite/json_graph/tree.py#L74-L75 
This check can be bypassed with specific inputs and cause a recursion error.

### Expected Behavior
<!--- Tell us what should happen -->
The code should check whether there are cycles with `root` as the source and raise an exception.
Another possible fix would be to check if the graph is not weakly connected.

### Steps to Reproduce
<!--- Provide a minimal example that reproduces the bug -->
```Python3
>>> import networkx as nx
>>> G = nx.DiGraph([(1, 2), (2, 3), (3, 1)])
>>> G.add_node(4)
>>> data = nx.json_graph.tree_data(G, 1)
RecursionError: maximum recursion depth exceeded
```

### Environment
<!--- Please provide details about your local environment -->
Python version: 3.8.10
NetworkX version: 2.7rc1.dev0


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `networkx/readwrite/json_graph/tree.py`
Content:
```
1 from itertools import chain
2 import networkx as nx
3 
4 __all__ = ["tree_data", "tree_graph"]
5 
6 
7 # NOTE: Remove attrs from signature in 3.0
8 def tree_data(G, root, attrs=None, ident="id", children="children"):
9     """Returns data in tree format that is suitable for JSON serialization
10     and use in Javascript documents.
11 
12     Parameters
13     ----------
14     G : NetworkX graph
15        G must be an oriented tree
16 
17     root : node
18        The root of the tree
19 
20     attrs : dict
21         A dictionary that contains two keys 'id' and 'children'. The
22         corresponding values provide the attribute names for storing
23         NetworkX-internal graph data. The values should be unique. Default
24         value: :samp:`dict(id='id', children='children')`.
25 
26         If some user-defined graph data use these attribute names as data keys,
27         they may be silently dropped.
28 
29         .. deprecated:: 2.6
30 
31            The `attrs` keyword argument is replaced by `ident` and `children`
32            and will be removed in networkx 3.0
33 
34     ident : string
35         Attribute name for storing NetworkX-internal graph data. `ident` must
36         have a different value than `children`. The default is 'id'.
37 
38     children : string
39         Attribute name for storing NetworkX-internal graph data. `children`
40         must have a different value than `ident`. The default is 'children'.
41 
42     Returns
43     -------
44     data : dict
45        A dictionary with node-link formatted data.
46 
47     Raises
48     ------
49     NetworkXError
50         If `children` and `ident` attributes are identical.
51 
52     Examples
53     --------
54     >>> from networkx.readwrite import json_graph
55     >>> G = nx.DiGraph([(1, 2)])
56     >>> data = json_graph.tree_data(G, root=1)
57 
58     To serialize with json
59 
60     >>> import json
61     >>> s = json.dumps(data)
62 
63     Notes
64     -----
65     Node attributes are stored in this format but keys
66     for attributes must be strings if you want to serialize with JSON.
67 
68     Graph and edge attributes are not stored.
69 
70     See Also
71     --------
72     tree_graph, node_link_data, adjacency_data
73     """
74     if G.number_of_nodes() != G.number_of_edges() + 1:
75         raise TypeError("G is not a tree.")
76     if not G.is_directed():
77         raise TypeError("G is not directed.")
78 
79     # NOTE: to be removed in 3.0
80     if attrs is not None:
81         import warnings
82 
83         msg = (
84             "\nThe `attrs` keyword argument of tree_data is deprecated\n"
85             "and will be removed in networkx 3.0.\n"
86             "It is replaced with explicit `ident` and `children` "
87             "keyword arguments.\n"
88             "To make this warning go away and ensure usage is forward\n"
89             "compatible, replace `attrs` with `ident` and `children,\n"
90             "for example:\n\n"
91             "    >>> tree_data(G, root, attrs={'id': 'foo', 'children': 'bar'})\n\n"
92             "should instead be written as\n\n"
93             "    >>> tree_data(G, root, ident='foo', children='bar')\n\n"
94             "The default values of 'id' and 'children' will not change."
95         )
96         warnings.warn(msg, DeprecationWarning, stacklevel=2)
97 
98         ident = attrs["id"]
99         children = attrs["children"]
100 
101     if ident == children:
102         raise nx.NetworkXError("The values for `id` and `children` must be different.")
103 
104     def add_children(n, G):
105         nbrs = G[n]
106         if len(nbrs) == 0:
107             return []
108         children_ = []
109         for child in nbrs:
110             d = dict(chain(G.nodes[child].items(), [(ident, child)]))
111             c = add_children(child, G)
112             if c:
113                 d[children] = c
114             children_.append(d)
115         return children_
116 
117     data = dict(chain(G.nodes[root].items(), [(ident, root)]))
118     data[children] = add_children(root, G)
119     return data
120 
121 
122 def tree_graph(data, attrs=None, ident="id", children="children"):
123     """Returns graph from tree data format.
124 
125     Parameters
126     ----------
127     data : dict
128         Tree formatted graph data
129     attrs : dict
130         A dictionary that contains two keys 'id' and 'children'. The
131         corresponding values provide the attribute names for storing
132         NetworkX-internal graph data. The values should be unique. Default
133         value: :samp:`dict(id='id', children='children')`.
134 
135         .. deprecated:: 2.6
136 
137            The `attrs` keyword argument is replaced by `ident` and `children`
138            and will be removed in networkx 3.0
139 
140     ident : string
141         Attribute name for storing NetworkX-internal graph data. `ident` must
142         have a different value than `children`. The default is 'id'.
143 
144     children : string
145         Attribute name for storing NetworkX-internal graph data. `children`
146         must have a different value than `ident`. The default is 'children'.
147 
148     Returns
149     -------
150     G : NetworkX DiGraph
151 
152     Examples
153     --------
154     >>> from networkx.readwrite import json_graph
155     >>> G = nx.DiGraph([(1, 2)])
156     >>> data = json_graph.tree_data(G, root=1)
157     >>> H = json_graph.tree_graph(data)
158 
159     See Also
160     --------
161     tree_data, node_link_data, adjacency_data
162     """
163     graph = nx.DiGraph()
164     if attrs is not None:
165         import warnings
166 
167         msg = (
168             "\nThe `attrs` keyword argument of tree_graph is deprecated\n"
169             "and will be removed in networkx 3.0.\n"
170             "It is replaced with explicit `ident` and `children` "
171             "keyword arguments.\n"
172             "To make this warning go away and ensure usage is\n"
173             "forward compatible, replace `attrs` with `ident` and `children,\n"
174             "for example:\n\n"
175             "    >>> tree_graph(data, attrs={'id': 'foo', 'children': 'bar'})\n\n"
176             "should instead be written as\n\n"
177             "    >>> tree_graph(data, ident='foo', children='bar')\n\n"
178             "The default values of 'id' and 'children' will not change."
179         )
180         warnings.warn(msg, DeprecationWarning, stacklevel=2)
181 
182         ident = attrs["id"]
183         children = attrs["children"]
184 
185     def add_children(parent, children_):
186         for data in children_:
187             child = data[ident]
188             graph.add_edge(parent, child)
189             grandchildren = data.get(children, [])
190             if grandchildren:
191                 add_children(child, grandchildren)
192             nodedata = {
193                 str(k): v for k, v in data.items() if k != ident and k != children
194             }
195             graph.add_node(child, **nodedata)
196 
197     root = data[ident]
198     children_ = data.get(children, [])
199     nodedata = {str(k): v for k, v in data.items() if k != ident and k != children}
200     graph.add_node(root, **nodedata)
201     add_children(root, children_)
202     return graph
203
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/networkx/readwrite/json_graph/tree.py b/networkx/readwrite/json_graph/tree.py
--- a/networkx/readwrite/json_graph/tree.py
+++ b/networkx/readwrite/json_graph/tree.py
@@ -75,6 +75,8 @@
         raise TypeError("G is not a tree.")
     if not G.is_directed():
         raise TypeError("G is not directed.")
+    if not nx.is_weakly_connected(G):
+        raise TypeError("G is not weakly connected.")
 
     # NOTE: to be removed in 3.0
     if attrs is not None:

{"golden_diff": "diff --git a/networkx/readwrite/json_graph/tree.py b/networkx/readwrite/json_graph/tree.py\n--- a/networkx/readwrite/json_graph/tree.py\n+++ b/networkx/readwrite/json_graph/tree.py\n@@ -75,6 +75,8 @@\n         raise TypeError(\"G is not a tree.\")\n     if not G.is_directed():\n         raise TypeError(\"G is not directed.\")\n+    if not nx.is_weakly_connected(G):\n+        raise TypeError(\"G is not weakly connected.\")\n \n     # NOTE: to be removed in 3.0\n     if attrs is not None:\n", "issue": "`json_graph.tree_data` can cause maximum recursion depth error.\n<!-- If you have a general question about NetworkX, please use the discussions tab to create a new discussion -->\r\n\r\n<!--- Provide a general summary of the issue in the Title above -->\r\n\r\n### Current Behavior\r\n<!--- Tell us what happens instead of the expected behavior -->\r\nCurrently the algorithm compares the `n_nodes` with `n_edges` to check if `G` is a tree. https://github.com/networkx/networkx/blob/0cc70051fa0a979b1f1eab4af5b6587a6ebf8334/networkx/readwrite/json_graph/tree.py#L74-L75 \r\nThis check can be bypassed with specific inputs and cause a recursion error.\r\n\r\n### Expected Behavior\r\n<!--- Tell us what should happen -->\r\nThe code should check whether there are cycles with `root` as the source and raise an exception.\r\nAnother possible fix would be to check if the graph is not weakly connected.\r\n\r\n### Steps to Reproduce\r\n<!--- Provide a minimal example that reproduces the bug -->\r\n```Python3\r\n>>> import networkx as nx\r\n>>> G = nx.DiGraph([(1, 2), (2, 3), (3, 1)])\r\n>>> G.add_node(4)\r\n>>> data = nx.json_graph.tree_data(G, 1)\r\nRecursionError: maximum recursion depth exceeded\r\n```\r\n\r\n### Environment\r\n<!--- Please provide details about your local environment -->\r\nPython version: 3.8.10\r\nNetworkX version: 2.7rc1.dev0\r\n\n", "before_files": [{"content": "from itertools import chain\nimport networkx as nx\n\n__all__ = [\"tree_data\", \"tree_graph\"]\n\n\n# NOTE: Remove attrs from signature in 3.0\ndef tree_data(G, root, attrs=None, ident=\"id\", children=\"children\"):\n    \"\"\"Returns data in tree format that is suitable for JSON serialization\n    and use in Javascript documents.\n\n    Parameters\n    ----------\n    G : NetworkX graph\n       G must be an oriented tree\n\n    root : node\n       The root of the tree\n\n    attrs : dict\n        A dictionary that contains two keys 'id' and 'children'. The\n        corresponding values provide the attribute names for storing\n        NetworkX-internal graph data. The values should be unique. Default\n        value: :samp:`dict(id='id', children='children')`.\n\n        If some user-defined graph data use these attribute names as data keys,\n        they may be silently dropped.\n\n        .. deprecated:: 2.6\n\n           The `attrs` keyword argument is replaced by `ident` and `children`\n           and will be removed in networkx 3.0\n\n    ident : string\n        Attribute name for storing NetworkX-internal graph data. `ident` must\n        have a different value than `children`. The default is 'id'.\n\n    children : string\n        Attribute name for storing NetworkX-internal graph data. `children`\n        must have a different value than `ident`. The default is 'children'.\n\n    Returns\n    -------\n    data : dict\n       A dictionary with node-link formatted data.\n\n    Raises\n    ------\n    NetworkXError\n        If `children` and `ident` attributes are identical.\n\n    Examples\n    --------\n    >>> from networkx.readwrite import json_graph\n    >>> G = nx.DiGraph([(1, 2)])\n    >>> data = json_graph.tree_data(G, root=1)\n\n    To serialize with json\n\n    >>> import json\n    >>> s = json.dumps(data)\n\n    Notes\n    -----\n    Node attributes are stored in this format but keys\n    for attributes must be strings if you want to serialize with JSON.\n\n    Graph and edge attributes are not stored.\n\n    See Also\n    --------\n    tree_graph, node_link_data, adjacency_data\n    \"\"\"\n    if G.number_of_nodes() != G.number_of_edges() + 1:\n        raise TypeError(\"G is not a tree.\")\n    if not G.is_directed():\n        raise TypeError(\"G is not directed.\")\n\n    # NOTE: to be removed in 3.0\n    if attrs is not None:\n        import warnings\n\n        msg = (\n            \"\\nThe `attrs` keyword argument of tree_data is deprecated\\n\"\n            \"and will be removed in networkx 3.0.\\n\"\n            \"It is replaced with explicit `ident` and `children` \"\n            \"keyword arguments.\\n\"\n            \"To make this warning go away and ensure usage is forward\\n\"\n            \"compatible, replace `attrs` with `ident` and `children,\\n\"\n            \"for example:\\n\\n\"\n            \"    >>> tree_data(G, root, attrs={'id': 'foo', 'children': 'bar'})\\n\\n\"\n            \"should instead be written as\\n\\n\"\n            \"    >>> tree_data(G, root, ident='foo', children='bar')\\n\\n\"\n            \"The default values of 'id' and 'children' will not change.\"\n        )\n        warnings.warn(msg, DeprecationWarning, stacklevel=2)\n\n        ident = attrs[\"id\"]\n        children = attrs[\"children\"]\n\n    if ident == children:\n        raise nx.NetworkXError(\"The values for `id` and `children` must be different.\")\n\n    def add_children(n, G):\n        nbrs = G[n]\n        if len(nbrs) == 0:\n            return []\n        children_ = []\n        for child in nbrs:\n            d = dict(chain(G.nodes[child].items(), [(ident, child)]))\n            c = add_children(child, G)\n            if c:\n                d[children] = c\n            children_.append(d)\n        return children_\n\n    data = dict(chain(G.nodes[root].items(), [(ident, root)]))\n    data[children] = add_children(root, G)\n    return data\n\n\ndef tree_graph(data, attrs=None, ident=\"id\", children=\"children\"):\n    \"\"\"Returns graph from tree data format.\n\n    Parameters\n    ----------\n    data : dict\n        Tree formatted graph data\n    attrs : dict\n        A dictionary that contains two keys 'id' and 'children'. The\n        corresponding values provide the attribute names for storing\n        NetworkX-internal graph data. The values should be unique. Default\n        value: :samp:`dict(id='id', children='children')`.\n\n        .. deprecated:: 2.6\n\n           The `attrs` keyword argument is replaced by `ident` and `children`\n           and will be removed in networkx 3.0\n\n    ident : string\n        Attribute name for storing NetworkX-internal graph data. `ident` must\n        have a different value than `children`. The default is 'id'.\n\n    children : string\n        Attribute name for storing NetworkX-internal graph data. `children`\n        must have a different value than `ident`. The default is 'children'.\n\n    Returns\n    -------\n    G : NetworkX DiGraph\n\n    Examples\n    --------\n    >>> from networkx.readwrite import json_graph\n    >>> G = nx.DiGraph([(1, 2)])\n    >>> data = json_graph.tree_data(G, root=1)\n    >>> H = json_graph.tree_graph(data)\n\n    See Also\n    --------\n    tree_data, node_link_data, adjacency_data\n    \"\"\"\n    graph = nx.DiGraph()\n    if attrs is not None:\n        import warnings\n\n        msg = (\n            \"\\nThe `attrs` keyword argument of tree_graph is deprecated\\n\"\n            \"and will be removed in networkx 3.0.\\n\"\n            \"It is replaced with explicit `ident` and `children` \"\n            \"keyword arguments.\\n\"\n            \"To make this warning go away and ensure usage is\\n\"\n            \"forward compatible, replace `attrs` with `ident` and `children,\\n\"\n            \"for example:\\n\\n\"\n            \"    >>> tree_graph(data, attrs={'id': 'foo', 'children': 'bar'})\\n\\n\"\n            \"should instead be written as\\n\\n\"\n            \"    >>> tree_graph(data, ident='foo', children='bar')\\n\\n\"\n            \"The default values of 'id' and 'children' will not change.\"\n        )\n        warnings.warn(msg, DeprecationWarning, stacklevel=2)\n\n        ident = attrs[\"id\"]\n        children = attrs[\"children\"]\n\n    def add_children(parent, children_):\n        for data in children_:\n            child = data[ident]\n            graph.add_edge(parent, child)\n            grandchildren = data.get(children, [])\n            if grandchildren:\n                add_children(child, grandchildren)\n            nodedata = {\n                str(k): v for k, v in data.items() if k != ident and k != children\n            }\n            graph.add_node(child, **nodedata)\n\n    root = data[ident]\n    children_ = data.get(children, [])\n    nodedata = {str(k): v for k, v in data.items() if k != ident and k != children}\n    graph.add_node(root, **nodedata)\n    add_children(root, children_)\n    return graph\n", "path": "networkx/readwrite/json_graph/tree.py"}], "after_files": [{"content": "from itertools import chain\nimport networkx as nx\n\n__all__ = [\"tree_data\", \"tree_graph\"]\n\n\n# NOTE: Remove attrs from signature in 3.0\ndef tree_data(G, root, attrs=None, ident=\"id\", children=\"children\"):\n    \"\"\"Returns data in tree format that is suitable for JSON serialization\n    and use in Javascript documents.\n\n    Parameters\n    ----------\n    G : NetworkX graph\n       G must be an oriented tree\n\n    root : node\n       The root of the tree\n\n    attrs : dict\n        A dictionary that contains two keys 'id' and 'children'. The\n        corresponding values provide the attribute names for storing\n        NetworkX-internal graph data. The values should be unique. Default\n        value: :samp:`dict(id='id', children='children')`.\n\n        If some user-defined graph data use these attribute names as data keys,\n        they may be silently dropped.\n\n        .. deprecated:: 2.6\n\n           The `attrs` keyword argument is replaced by `ident` and `children`\n           and will be removed in networkx 3.0\n\n    ident : string\n        Attribute name for storing NetworkX-internal graph data. `ident` must\n        have a different value than `children`. The default is 'id'.\n\n    children : string\n        Attribute name for storing NetworkX-internal graph data. `children`\n        must have a different value than `ident`. The default is 'children'.\n\n    Returns\n    -------\n    data : dict\n       A dictionary with node-link formatted data.\n\n    Raises\n    ------\n    NetworkXError\n        If `children` and `ident` attributes are identical.\n\n    Examples\n    --------\n    >>> from networkx.readwrite import json_graph\n    >>> G = nx.DiGraph([(1, 2)])\n    >>> data = json_graph.tree_data(G, root=1)\n\n    To serialize with json\n\n    >>> import json\n    >>> s = json.dumps(data)\n\n    Notes\n    -----\n    Node attributes are stored in this format but keys\n    for attributes must be strings if you want to serialize with JSON.\n\n    Graph and edge attributes are not stored.\n\n    See Also\n    --------\n    tree_graph, node_link_data, adjacency_data\n    \"\"\"\n    if G.number_of_nodes() != G.number_of_edges() + 1:\n        raise TypeError(\"G is not a tree.\")\n    if not G.is_directed():\n        raise TypeError(\"G is not directed.\")\n    if not nx.is_weakly_connected(G):\n        raise TypeError(\"G is not weakly connected.\")\n\n    # NOTE: to be removed in 3.0\n    if attrs is not None:\n        import warnings\n\n        msg = (\n            \"\\nThe `attrs` keyword argument of tree_data is deprecated\\n\"\n            \"and will be removed in networkx 3.0.\\n\"\n            \"It is replaced with explicit `ident` and `children` \"\n            \"keyword arguments.\\n\"\n            \"To make this warning go away and ensure usage is forward\\n\"\n            \"compatible, replace `attrs` with `ident` and `children,\\n\"\n            \"for example:\\n\\n\"\n            \"    >>> tree_data(G, root, attrs={'id': 'foo', 'children': 'bar'})\\n\\n\"\n            \"should instead be written as\\n\\n\"\n            \"    >>> tree_data(G, root, ident='foo', children='bar')\\n\\n\"\n            \"The default values of 'id' and 'children' will not change.\"\n        )\n        warnings.warn(msg, DeprecationWarning, stacklevel=2)\n\n        ident = attrs[\"id\"]\n        children = attrs[\"children\"]\n\n    if ident == children:\n        raise nx.NetworkXError(\"The values for `id` and `children` must be different.\")\n\n    def add_children(n, G):\n        nbrs = G[n]\n        if len(nbrs) == 0:\n            return []\n        children_ = []\n        for child in nbrs:\n            d = dict(chain(G.nodes[child].items(), [(ident, child)]))\n            c = add_children(child, G)\n            if c:\n                d[children] = c\n            children_.append(d)\n        return children_\n\n    data = dict(chain(G.nodes[root].items(), [(ident, root)]))\n    data[children] = add_children(root, G)\n    return data\n\n\ndef tree_graph(data, attrs=None, ident=\"id\", children=\"children\"):\n    \"\"\"Returns graph from tree data format.\n\n    Parameters\n    ----------\n    data : dict\n        Tree formatted graph data\n    attrs : dict\n        A dictionary that contains two keys 'id' and 'children'. The\n        corresponding values provide the attribute names for storing\n        NetworkX-internal graph data. The values should be unique. Default\n        value: :samp:`dict(id='id', children='children')`.\n\n        .. deprecated:: 2.6\n\n           The `attrs` keyword argument is replaced by `ident` and `children`\n           and will be removed in networkx 3.0\n\n    ident : string\n        Attribute name for storing NetworkX-internal graph data. `ident` must\n        have a different value than `children`. The default is 'id'.\n\n    children : string\n        Attribute name for storing NetworkX-internal graph data. `children`\n        must have a different value than `ident`. The default is 'children'.\n\n    Returns\n    -------\n    G : NetworkX DiGraph\n\n    Examples\n    --------\n    >>> from networkx.readwrite import json_graph\n    >>> G = nx.DiGraph([(1, 2)])\n    >>> data = json_graph.tree_data(G, root=1)\n    >>> H = json_graph.tree_graph(data)\n\n    See Also\n    --------\n    tree_data, node_link_data, adjacency_data\n    \"\"\"\n    graph = nx.DiGraph()\n    if attrs is not None:\n        import warnings\n\n        msg = (\n            \"\\nThe `attrs` keyword argument of tree_graph is deprecated\\n\"\n            \"and will be removed in networkx 3.0.\\n\"\n            \"It is replaced with explicit `ident` and `children` \"\n            \"keyword arguments.\\n\"\n            \"To make this warning go away and ensure usage is\\n\"\n            \"forward compatible, replace `attrs` with `ident` and `children,\\n\"\n            \"for example:\\n\\n\"\n            \"    >>> tree_graph(data, attrs={'id': 'foo', 'children': 'bar'})\\n\\n\"\n            \"should instead be written as\\n\\n\"\n            \"    >>> tree_graph(data, ident='foo', children='bar')\\n\\n\"\n            \"The default values of 'id' and 'children' will not change.\"\n        )\n        warnings.warn(msg, DeprecationWarning, stacklevel=2)\n\n        ident = attrs[\"id\"]\n        children = attrs[\"children\"]\n\n    def add_children(parent, children_):\n        for data in children_:\n            child = data[ident]\n            graph.add_edge(parent, child)\n            grandchildren = data.get(children, [])\n            if grandchildren:\n                add_children(child, grandchildren)\n            nodedata = {\n                str(k): v for k, v in data.items() if k != ident and k != children\n            }\n            graph.add_node(child, **nodedata)\n\n    root = data[ident]\n    children_ = data.get(children, [])\n    nodedata = {str(k): v for k, v in data.items() if k != ident and k != children}\n    graph.add_node(root, **nodedata)\n    add_children(root, children_)\n    return graph\n", "path": "networkx/readwrite/json_graph/tree.py"}]}