Coverage for scripts / live_release_validation / json_utils.py: 100.00%
12 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-09-14 22:07 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-09-14 22:07 +0000
1"""Strict JSON decoding helpers for security-sensitive validation state."""
3from __future__ import annotations
5import json
6from typing import Any
9def _reject_duplicate_keys(pairs: list[tuple[str, Any]]) -> dict[str, Any]:
10 value: dict[str, Any] = {}
11 for key, item in pairs:
12 if key in value:
13 raise ValueError(f"duplicate JSON key: {key}")
14 value[key] = item
15 return value
18def loads_without_duplicate_keys(value: str) -> Any:
19 """Decode JSON while rejecting duplicate keys at every object depth."""
20 return json.loads(value, object_pairs_hook=_reject_duplicate_keys)