Skip to main content

serialize_unknown

No overview available.

def serialize_unknown(
obj: Any
) - > Union[dict, str]

Converts non-standard Python objects into JSON-serializable formats by attempting to access their internal dictionary or converting them to strings. Use this as a fallback handler for JSON encoders to prevent serialization errors when encountering custom class instances.

Parameters

NameTypeDescription
objAnyThe object instance that the standard JSON encoder is unable to process.

Returns

TypeDescription
Union[dict, str]A dictionary representation of the object's attributes if available, otherwise the string representation of the object.