import json


def jit_data(G, indent=None, default=None):
    """Returns data in JIT JSON format.

    Parameters
    ----------
    G : NetworkX Graph

    indent: optional, default=None
        If indent is a non-negative integer, then JSON array elements and
        object members will be pretty-printed with that indent level.
        An indent level of 0, or negative, will only insert newlines.
        None (the default) selects the most compact representation.

    default: optional, default=None
         It will pass the value to the json.dumps function in order to
         be able to serialize custom objects used as nodes.

    Returns
    -------
    data: JIT JSON string
    """
    json_graph = []
    for node in G.nodes():
        json_node = {
            "id": node,
            "name": node
        }
        # node data
        json_node["data"] = G.nodes[node]
        # adjacencies
        if G[node]:
            json_node["adjacencies"] = []
            for neighbour in G[node]:
                adjacency = {
                    "nodeTo": neighbour,
                }
                # adjacency data
                adjacency["data"] = G.edges[node, neighbour]
                json_node["adjacencies"].append(adjacency)
        json_graph.append(json_node)
    return json.dumps(json_graph, indent=indent, default=default)