title: convert directed graph to Json file python
body: <p>I'm Converting dictionary to a directed graph then I'm trying saving that graph as a JSON file in this code:</p>
  
  <pre><code>def main():
      g = {"a": ["d"],
           "b": ["c"],
           "c": ["b", "c", "d", "e"],
           "d": ["a", "c"],
           "e": ["c"],
           "f": []
           }
  
      graph = DirectedGraph()
      for key in g.keys():
          graph.add(key)
          elements = g[key]
          for child in elements:
              graph.add_edge(key, child)
  
      with open('JJ.json', 'w') as output_file:
          json.dump(graph, output_file)
  
  
  main()
  </code></pre>
  
  <p>Its giving me an error at json.dump as </p>
  
  <blockquote>
    <p>Object of type 'DirectedGraph' is not JSON serializable</p>
  </blockquote>
  
  <p>How can I fix it?</p>