Reject Duplicate JSON Keys Before Validating a Record
A technical article explains why validating only the dictionary produced by a JSON decoder can miss repeated member names, since the duplicate may vanish during decoding. It recommends inspecting key-value pairs during decoding, using Python's object_pairs_hook to detect repeats at every nesting level. The article presents a teaching parser that enforces a 4,096-byte UTF-8 limit, requires a top-level object, rejects non-finite constants like NaN, and parses decimals as Decimal values. The example code was tested locally on Python 3.12 with six cases, using invented fixtures rather than production data. The author notes that this decoding check is separate from application-level schema and range validation, which should be tested independently.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in