Skip to main content

_default

Converts various Python objects into JSON-serializable formats, specifically handling dates, decimals, UUIDs, dataclasses, and objects with an html method.

def _default(
o: t.Any
) - > t.Any

Provides a fallback serialization mechanism for objects not natively supported by the standard JSON encoder. Converts dates to HTTP-formatted strings, Decimals and UUIDs to strings, dataclasses to dictionaries, and HTML-capable objects to their string representation.

Parameters

NameTypeDescription
ot.AnyThe object instance to be converted into a JSON-compatible format.

Returns

TypeDescription
t.AnyA JSON-serializable representation of the input object, such as a string or dictionary.