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

1"""Strict JSON decoding helpers for security-sensitive validation state.""" 

2 

3from __future__ import annotations 

4 

5import json 

6from typing import Any 

7 

8 

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 

16 

17 

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)