import json


SENSITIVE_KEYS = {
    "access_token",
    "authorization",
    "card_number",
    "client_secret",
    "cvv",
    "passport",
    "passport_number",
    "payment",
    "secret",
    "token",
}


def redact(value):
    if isinstance(value, dict):
        clean = {}
        for key, item in value.items():
            if str(key).lower() in SENSITIVE_KEYS:
                clean[key] = "[redacted]"
            else:
                clean[key] = redact(item)
        return clean
    if isinstance(value, list):
        return [redact(item) for item in value]
    return value


def safe_json(value):
    return json.dumps(redact(value), ensure_ascii=False, default=str)
