"""boundary/json.py - establish trusted types at the JSON input boundary.

WHY:
    Companion to boundary/toml.py. Parsed JSON arrives as opaque
    object / dict[str, Any]; this is the single point where JSON bytes become
    Python objects, so it is the right place to establish types.
"""

import json
from pathlib import Path

from accountable_record.boundary.toml import is_list, is_table

__all__ = ["is_list", "is_table", "load_json"]


def load_json(path: Path) -> dict[str, object]:
    """Load JSON from a path, establishing dict[str, object] at the boundary."""
    data = json.loads(path.read_text(encoding="utf-8"))
    if not is_table(data):
        msg = f"JSON root is not an object: {path}"
        raise ValueError(msg)
    return data
