|View source on GitHub|
Write a JSON file containing a representation of obj.
cirq.protocols.to_json( obj: Any, file_or_fn: Union[None, IO, pathlib.Path, str] = None, *, indent: int = 2, cls: Type[json.JSONEncoder] = cirq.protocols.json_serialization.CirqEncoder ) -> Optional[str]
Used in the notebooks
|Used in the tutorials|
The object may be a cirq object or have data members that are cirq objects which implement the SupportsJSON protocol.
||An object which can be serialized to a JSON representation.|
A filename (if a string or
||Pretty-print the resulting file with this indent level. Passed to json.dump.|
||Passed to json.dump; the default value of CirqEncoder enables the serialization of Cirq objects which implement the SupportsJSON protocol. To support serialization of 3rd party classes, prefer adding the _jsondict magic method to your classes rather than overriding this default.|