Skip to main content

_default

Converts various Python objects into JSON-serializable formats, specifically handling dates as HTTP dates, Decimals and UUIDs as strings, dataclasses as dictionaries, and objects with an html method as strings.

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

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

Parameters

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

Returns

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