code: def to_json(self):
          
          obj = {
              "vertices": [
                  {
                      "id": vertex.id,
                      "annotation": vertex.annotation,
                  }
                  for vertex in self.vertices
              ],
              "edges": [
                  {
                      "id": edge.id,
                      "annotation": edge.annotation,
                      "head": edge.head,
                      "tail": edge.tail,
                  }
                  for edge in self._edges
              ],
          }
          # Ensure that we always return unicode output on Python 2.
          return six.text_type(json.dumps(obj, ensure_ascii=False))
docs: Convert to a JSON string.