import datetime
import decimal
import json
from typing import Any


def json_safe(content: Any) -> Any:
    """Make sure any response data is json-safe"""

    def custom_default(out):
        if isinstance(out, (datetime.date, datetime.datetime)):
            return out.isoformat()

        if isinstance(out, decimal.Decimal):
            return float(out)

    return json.loads(
        json.dumps(
            content,
            ensure_ascii=False,
            allow_nan=False,
            indent=None,
            separators=(",", ":"),
            default=custom_default,
        )
    )
