Source code for networkx.readwrite.json_graph.node_link

import warnings
from itertools import count

import networkx as nx

__all__ = ["node_link_data", "node_link_graph"]


def _to_tuple(x):
    """Converts lists to tuples, including nested lists.

    All other non-list inputs are passed through unmodified. This function is
    intended to be used to convert potentially nested lists from json files
    into valid nodes.

    Examples
    --------
    >>> _to_tuple([1, 2, [3, 4]])
    (1, 2, (3, 4))
    """
    if not isinstance(x, tuple | list):
        return x
    return tuple(map(_to_tuple, x))