Module ImportFrom alias alias Import alias Import alias identifier Assign NameStore Str Assign NameStore ListLoad Str Str FunctionDef arguments args NameParam NameParam defaults body Expr Str If UnaryOpNot CompareEq Call AttributeLoad NameLoad attr BinOpAdd Call AttributeLoad NameLoad attr Num body Raise Call NameLoad Str If UnaryOpNot Call AttributeLoad NameLoad attr body Raise Call NameLoad Str FunctionDef arguments args NameParam NameParam defaults body Assign NameStore SubscriptLoad NameLoad Index NameLoad If CompareEq Call NameLoad NameLoad Num body Return ListLoad Assign NameStore ListLoad For NameStore NameLoad body Assign NameStore Call NameLoad keyword NameLoad SubscriptLoad AttributeLoad NameLoad attr Index NameLoad Assign NameStore Call NameLoad NameLoad NameLoad If NameLoad body Assign SubscriptStore NameLoad Index Str NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Return NameLoad decorator_list Assign NameStore Call NameLoad keyword NameLoad SubscriptLoad AttributeLoad NameLoad attr Index NameLoad Assign SubscriptStore NameLoad Index Str Call NameLoad NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr FunctionDef arguments args NameParam NameParam defaults body For NameStore NameLoad body Assign NameStore SubscriptLoad NameLoad Index Str Expr Call AttributeLoad NameLoad attr NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr Str ListLoad If NameLoad body Expr Call NameLoad NameLoad NameLoad Assign NameStore Call NameLoad GeneratorExp TupleLoad Call NameLoad NameLoad NameLoad comprehension TupleStore NameStore NameStore Call AttributeLoad NameLoad attr BoolOpAnd CompareNotEq NameLoad Str CompareNotEq NameLoad Str Expr Call AttributeLoad NameLoad attr NameLoad keyword NameLoad decorator_list Assign NameStore SubscriptLoad NameLoad Index Str Assign NameStore Call AttributeLoad NameLoad attr Str ListLoad Assign NameStore Call NameLoad GeneratorExp TupleLoad NameLoad NameLoad comprehension TupleStore NameStore NameStore Call AttributeLoad NameLoad attr BoolOpAnd CompareNotEq NameLoad Str CompareNotEq NameLoad Str Expr Call AttributeLoad NameLoad attr NameLoad keyword NameLoad Expr Call NameLoad NameLoad NameLoad Return NameLoad decorator_list
N/A itertools count repeat N/A json N/A networkx nx N/A __author__ Aric Hagberg (hagberg@lanl.gov)) N/A __all__ N/A tree_data tree_graph tree_data N/A N/A G root N/A N/A N/A Return data in tree format that is suitable for JSON serialization
    and use in Javascript documents.

    Parameters
    ----------
    G : NetworkX graph
       G must be an oriented tree

    root : node
       The root of the tree

    Returns
    -------
    data : dict
       A dictionary with node-link formatted data.

    Examples
    --------
    >>> from networkx.readwrite import json_graph
    >>> G = nx.DiGraph([(1,2)])
    >>> data = json_graph.tree_data(G,root=1)

    To serialize with json

    >>> import json
    >>> s = json.dumps(data)
    
    Notes
    -----
    Node attributes are stored in this format but keys 
    for attributes must be strings if you want to serialize with JSON.
    
    Graph and edge attributes are not stored.

    See Also
    --------
    tree_graph, node_link_data, node_link_data
     N/A N/A N/A N/A N/A G number_of_nodes N/A N/A N/A G number_of_edges 1 N/A N/A N/A TypeError G is not a tree. N/A N/A N/A N/A G is_directed N/A N/A N/A TypeError G is not directed add_children N/A N/A n G N/A N/A N/A nbrs N/A G N/A n N/A N/A N/A len nbrs 0 N/A N/A N/A N/A children N/A N/A child nbrs N/A N/A d N/A dict id child N/A N/A G node N/A child N/A c N/A add_children child G N/A c N/A N/A N/A d N/A children c N/A N/A N/A children append d N/A children N/A N/A data N/A dict id root N/A N/A G node N/A root N/A N/A data N/A children N/A add_children root G N/A data N/A tree_graph N/A N/A data N/A N/A N/A Return graph from tree data format. 

    Parameters
    ----------
    data : dict
        Tree formatted graph data
    
    Returns
    -------
    G : NetworkX DiGraph

    Examples
    --------
    >>> from networkx.readwrite import json_graph
    >>> G = nx.DiGraph([(1,2)])
    >>> data = json_graph.tree_data(G,root=1)
    >>> H = json_graph.tree_graph(data)

    See Also
    --------
    tree_graph, node_link_data, adjacency_data
     N/A graph N/A N/A nx DiGraph add_children N/A N/A parent children N/A N/A N/A data children N/A N/A child N/A data N/A id N/A N/A N/A graph add_edge parent child N/A grandchildren N/A N/A data get children N/A N/A grandchildren N/A N/A N/A add_children child grandchildren N/A nodedata N/A dict N/A N/A N/A str k v N/A N/A k v N/A N/A data items N/A N/A k id N/A k children N/A N/A N/A graph add_node child attr_dict nodedata N/A N/A root N/A data N/A id N/A children N/A N/A data get children N/A N/A nodedata N/A dict N/A N/A k v N/A N/A k v N/A N/A data items N/A N/A k id N/A k children N/A N/A N/A graph add_node root attr_dict nodedata N/A N/A add_children root children N/A graph N/A