haive.core.graph.common.serialization

Utilities for serialization and deserialization.

Functions

ensure_serializable(obj)

Ensure an object can be serialized to JSON.

from_json(json_str[, target_cls])

Convert a JSON string to an object.

to_json(obj, **kwargs)

Convert an object to a JSON string.

Module Contents

haive.core.graph.common.serialization.ensure_serializable(obj)[source]

Ensure an object can be serialized to JSON.

Parameters:

obj (Any) – Object to make serializable

Returns:

JSON-serializable version of the object

Return type:

Any

haive.core.graph.common.serialization.from_json(json_str, target_cls=None)[source]

Convert a JSON string to an object.

Parameters:
  • json_str (str) – JSON string to deserialize

  • target_cls (type | None) – Optional target class

Returns:

Deserialized object

Return type:

Any

haive.core.graph.common.serialization.to_json(obj, **kwargs)[source]

Convert an object to a JSON string.

Parameters:
  • obj (Any) – Object to serialize

  • **kwargs – Additional arguments for json.dumps

Returns:

JSON string

Return type:

str