def serialize_to_json(obj: Any, check_object: bool = False, make_absolute: bool = True) -> dict:
    """Serialize a Python object into a JSON dict. Also serializes functions and objects."""
    if isinstance(obj, BaseModel):
        raw_json = obj.json(encoder=partial(_expanded_default, None, make_absolute))
    else:
        raw_json = config_json_dumps(obj, make_absolute=make_absolute)
    if check_object:
        try:
            config_json_loads(raw_json)
        except ValueError as e:
            e = str(e)
            if "user_script" in e:
                e = e.replace("Cannot load", "Cannot serialize")
                e = e.replace("from JSON", "to JSON")
            raise ValueError(e) from None
    return json.loads(raw_json)
Serialize a Python object into a JSON dict. Also serializes functions and objects.
olive/common/config_utils.py