... str):
    s = s.strip()
    if not s:
        raise ValueError("empty response")

    # 1. Direkt versuchen
    try:
        return json.loads(s)
    except Exception:
        pass

    # 2. Erste { ... }-Spanne manuell extrahieren (ohne Regex-Rekursion)
    start = s.find("{")
    end = s.rfind("}")
    if start == -1 or end == -1 or end <= start:
        raise ValueError("no JSON object found")

 ...