import json
from networkx.readwrite import json_graph


def write_nxgraph_to_json(g, output):
    """
    Write a networkx graph as JSON to the specified output

    Args:
        g (networkx.Graph): graph to write as JSON
        output (filelike): output to write to
    """

    jsond = json_graph.node_link_data(g)
    return json.dump(jsond, output)