Skip to content

json_encoder

json_encoder

Implementation of custom JSON encoder.

JSONEncoder

Bases: JSONEncoder

JSON Encoder class.

default

default(obj: object) -> object

Encode object default method.

Parameters:

  • obj (object) –

    Object to encode.

Returns:

  • JSON encoded object –
Source code in src/console/utilities/json_encoder.py
def default(self, obj: object) -> object:
    """Encode object default method.

    Parameters
    ----------
    obj : object
        Object to encode.

    Returns
    -------
        JSON encoded object
    """
    if dataclasses.is_dataclass(obj) and not isinstance(obj, type):
        return dataclasses.asdict(obj)
    if isinstance(obj, Path):
        return str(obj)
    return super().default(obj)