<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_json(self):
 """ Convert to a JSON string. """

        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))