def _parse_legacy_circuit_json(self, json_str: str) -> list[Operation]:
        """Converts a legacy JSON circuit representation.

        Converts a JSON created for the legacy API into one that will work
        with the Arnica v1 API.

        Raises:
            ValueError:
                * if there is not exactly one measurement operation at the end
                    of the circuit.

                * if an operation is found in json_str that is not in
                    OperationString.

        Args:
            json_str: A JSON-formatted string that could be used as the
                data parameter in the body of a request to the old AQT API.
        """
        circuit = []
        number_of_measurements = 0
        instruction: Operation

        for legacy_op in json.loads(json_str):
            if number_of_measurements > 0:
                raise ValueError("Need exactly one `MEASURE` operation at the end of the circuit.")

            if legacy_op[0] == OperationString.Z.value:
                instruction = GateRZ(operation="RZ", qubit=legacy_op[2][0], phi=legacy_op[1])

            elif legacy_op[0] == OperationString.R.value:
                instruction = GateR(
                    operation="R", qubit=legacy_op[3][0], theta=legacy_op[1], phi=legacy_op[2]
                )

            elif legacy_op[0] == OperationString.MS.value:
                instruction = GateRXX(operation="RXX", qubits=legacy_op[2], theta=legacy_op[1])

            elif legacy_op[0] == OperationString.MEASURE.value:
                instruction = Measure(operation="MEASURE")
                number_of_measurements += 1

            else:
                raise ValueError(f'Got unknown gate on operation: {legacy_op}.')

            circuit.append(instruction)

        if circuit[-1]["operation"] != "MEASURE":
            circuit.append({"operation": "MEASURE"})

        return circuit
Converts a legacy JSON circuit representation.

        Converts a JSON created for the legacy API into one that will work
        with the Arnica v1 API.

        Raises:
            ValueError:
                * if there is not exactly one measurement operation at the end
                    of the circuit.

                * if an operation is found in json_str that is not in
                    OperationString.

        Args:
            json_str: A JSON-formatted string that could be used as the
                data parameter in the body of a request to the old AQT API.
        
cirq-aqt/cirq_aqt/aqt_sampler.py