Skip to content

serialization

Helpers for JSON serialization of experiments.

ObjectJSONEncoder

Bases: JSONEncoder

Class for encoding in JSON.

default

default(o)

JSON encoder.

from_json

from_json(json_info)

Load data from JSON.

to_json

to_json(object: Any, path: None = None) -> str
to_json(object: Any, path: Path) -> Path
to_json(object, path=None)

Serialize to JSON.

The object is encoded before the file is written, so a value which cannot be encoded leaves no truncated file.

Parameters:

Name Type Description Default
object Any

the object to serialize.

required
path Path | None

the file to write, None for the JSON as a string.

None

Returns:

Type Description
str | Path

The JSON, or the path of the file it was written to.

Raises:

Type Description
TypeError

for a value which ObjectJSONEncoder cannot encode.