penfever's picture
Release native-format structure-closure validation cohort
44353e7 verified
Raw History Blame Contribute Delete
396 Bytes
# Copyright The Marin Authors
# SPDX-License-Identifier: Apache-2.0
"""Reject ambiguous duplicate keys while decoding trusted JSON objects."""
def unique_object(pairs: list[tuple[str, object]]) -> dict[str, object]:
result = {}
for key, value in pairs:
if key in result:
raise ValueError(f"duplicate JSON key {key!r}")
result[key] = value
return result