diff --git a/pyzx/graph/jsonparser.py b/pyzx/graph/jsonparser.py index 2d3fe3b1..d3955893 100644 --- a/pyzx/graph/jsonparser.py +++ b/pyzx/graph/jsonparser.py @@ -71,10 +71,13 @@ def _new_var(name: str) -> Poly: except Exception as e: raise ValueError(e) -def json_to_graph(js: str, backend:Optional[str]=None) -> BaseGraph: +def json_to_graph(js: str|dict[str,Any], backend:Optional[str]=None) -> BaseGraph: """Converts the json representation of a .qgraph Quantomatic graph into - a pyzx graph.""" - j = json.loads(js, cls=ComplexDecoder) + a pyzx graph. If JSON is given as a string, parse it first.""" + if isinstance(js, str): + j = json.loads(js, cls=ComplexDecoder) + else: + j = js g = Graph(backend) g.variable_types = j.get('variable_types',{})