from pathlib import Path import json CONFIG = Path("config.json") def load_config(path: Path = CONFIG) -> dict: try: return json.loads(path.read_text(encoding="utf-8")) except FileNotFoundError: return {"debug": False, "port": 8000} except json.JSONDecodeError as exc: raise ValueError(f"invalid JSON at line {exc.lineno}") from exc print(load_config())