yera.typing.serialisation
Pydantic-based serialization utilities for enhanced type support.
Symbols
canonicalise_json
canonicalise_json(
payload: bytes | str,
) → strNormalize a JSON payload into Yera's canonical representation.
Parameters
JSON text to parse and normalize.
Returns
Compact JSON with deterministic object-key ordering.
Raises
If the payload is not valid finite JSON.
deserialise
deserialise(
raw: bytes | str,
type_hint: type,
) → objectDeserialise a JSON string or bytes into a Python object per the type hint.
Parameters
The JSON-encoded data (bytes or str).
The target type annotation.
Returns
The deserialised Python object.
Raises
If type_hint is not supported.
If deserialisation fails.
serialise
serialise(
value: object,
type_hint: type,
) → bytes | strSerialise a value to JSON using the given type hint.
Parameters
The Python object to serialise.
The type annotation guiding serialisation.
Returns
A JSON-encoded byte string.
Raises
If type_hint is not supported.
serialise_runtime_value
serialise_runtime_value(
value: object,
) → strSerialize a heterogeneous runtime value to JSON.
Unlike type-derived serialization, this function supports empty and heterogeneous nested collections whose complete type cannot be inferred from their runtime contents. Supported leaf values are serialized through Yera's normal typing infrastructure.
This representation is intended for display and model-context transport. It does not retain sufficient type information for deserialization back into every original Python container type.
Parameters
A runtime value containing Yera-supported leaves.
Returns
Compact JSON containing the normalized runtime value.
Raises
If the value contains a leaf unsupported by Yera's typing infrastructure.
If a supported leaf cannot be serialized.
serialise_value
serialise_value(
value: object,
) → SerialisedValueDerive and serialize a supported runtime value.
Parameters
A populated runtime value accepted by Yera's typing system.
Returns
The derived type information, serialized payload, and JSON Schema.
Raises
If the value's supported type cannot be derived.
If the value does not conform to its derived type.
SerialisedValue
A runtime value serialized with its derived type information.
Attributes
The supported Yera type derived from the runtime object.
Human-readable rendering of the derived type.
JSON produced by Yera's serialization infrastructure.
Serialization-mode JSON Schema for the derived type.
type_schema
type_schema(
type_hint: type,
) → dict[str, object]Return the serialization schema for a supported declared type.
Parameters
The declared type whose schema should be generated.
Returns
A JSON Schema describing the serialized representation.
Raises
If the declared type is not supported.