Read a JSON graph after applying Graphify's graph-load size cap.
(path: str | Path)
| 269 | |
| 270 | |
| 271 | def _read_json_file(path: str | Path) -> dict[str, Any]: |
| 272 | """Read a JSON graph after applying Graphify's graph-load size cap.""" |
| 273 | from graphify.security import check_graph_file_size_cap |
| 274 | |
| 275 | json_path = Path(path) |
| 276 | check_graph_file_size_cap(json_path) |
| 277 | try: |
| 278 | data = json.loads(json_path.read_text(encoding="utf-8")) |
| 279 | except (json.JSONDecodeError, OSError) as exc: |
| 280 | raise RuntimeError( |
| 281 | f"Cannot parse {json_path}: {exc}. " |
| 282 | "The file may be corrupted — re-run 'graphify extract'." |
| 283 | ) from exc |
| 284 | if not isinstance(data, dict): |
| 285 | raise ValueError("diagnostic input must be a JSON object") |
| 286 | return data |
| 287 | |
| 288 | |
| 289 | def diagnose_file( |