Check the text before the evidence disappears.
Imagine an AI draft describing a fictional document. Its raw JSON contains {"status":"draft","status":"ready"}. Which status reaches your workflow? In our local Python run, the default decoder kept ready. The original disagreement vanished from the resulting dictionary.
This is an authored example, not a captured model response. Professionals can use it to review an ingestion boundary. Hobbyists can run the kit without an AI account. Skeptics can inspect a reproducible failure mode without accepting a claim about model quality.
RFC 8259, section 4 recommends unique member names and describes inconsistent handling of repeats across implementations. Rejecting repeats is our chosen application policy.
A parsed dictionary may already be too late.
Start with the original response text at a boundary you control. If an SDK has already converted it to a dictionary, serializing that dictionary and checking it again cannot restore discarded members. Our exercise demonstrates this loss explicitly.
Retain the original text according to your data-handling policy. On a duplicate-key error, stop that handoff and return a visible review result. Do not guess which value was intended or let the rejected draft drive an action.
The hook below handles each object independently: two separate objects may both have a status field. Repeating the field within one object is the condition we reject.
Inspect the kit, then run the cases.
Use an existing Python 3.10+ installation. We ran Windows Python 3.13.15. No third-party package or API key is needed. The first PowerShell block creates a fresh directory; choose another name if it already exists.
New-Item -ItemType Directory -Path .\json-keys-practice-2026-11-01 -ErrorAction Stop
Set-Location .\json-keys-practice-2026-11-01
Invoke-WebRequest 'https://jabsystems.io/ai-anonymous/Social/two-answers-practice.zip' -OutFile .\practice.zip
Expand-Archive -LiteralPath .\practice.zip -DestinationPath .\practice
Get-Content .\practice\json-keys-practice-readme.txt
Get-Content .\practice\check-json-keys.pyRead the downloaded README and script before running the next block. The download uses the network; the exercise itself uses only authored strings and the Python standard library.
python --version
python .\practice\check-json-keys.py | Set-Content -Encoding utf8 .\my-results.json
Get-Content .\my-results.jsonRun normally, without python -O, so the exercise assertions remain enabled. Compare your result with the recorded report in the kit; the Python version field may differ.
Keep the pairs long enough to check them.
import json
def unique_object(pairs):
result = {}
for key, value in pairs:
if key in result:
raise ValueError(f"duplicate key: {key!r}")
result[key] = value
return result
raw = '{"status":"draft","status":"ready"}'
print(json.loads(raw))
try:
json.loads(raw, object_pairs_hook=unique_object)
except ValueError as error:
print(error)This smaller snippet printed {'status': 'ready'}, then duplicate key: 'status'. The Python decoding reference documents object_pairs_hook, which receives each object's decoded name/value pairs before the ordinary dictionary is returned. Our function refuses an already-seen name.
The decoder's strict option concerns control characters in strings. In our run, strict=True still kept the last duplicate. It is not this duplicate-name policy.
What the ten local cases showed.
The complete downloaded script asserts these outcomes:
- Unique names: parsed with both fields preserved.
- Conflicting or identical repeated values: rejected as
duplicate_key. - A duplicate inside a nested object or an object in an array: rejected.
statusand\u0073tatusin the same object: rejected after decoding the escaped name.- One status in each of two separate objects: parsed.
statusandStatus: parsed as distinct names.- A trailing comma: rejected as
invalid_json. - An object missing status: parsed. This check does not require that field.
All ten authored cases passed on the stated environment. The script separately confirmed default last-value behavior, strict=True last-value behavior, and the inability to rediscover a duplicate after a lossy decode. Download the actual local report. The count covers finite fixture assertions, not all inputs.
Unique keys do not make the answer true.
Our hook compares decoded Python string keys. It does not fold case or normalize Unicode, apply field/type rules, verify facts, or grant permission. A successfully parsed ready value could still be wrong.
This is one early check before the separate schema-validation step. A schema applied to an ordinary dictionary cannot inspect members that a previous decoder discarded.
It is also not a complete JSON hardening layer: define independent policies for input size, nesting, number ranges, NaN/Infinity and Unicode handling. Python's interoperability notes describe accepted extensions and implementation limits. This kit intentionally focuses on duplicate names.
Tested: ten authored cases, the smaller snippet and the extracted download workflow on Windows. Not tested: model output, a real SDK response path, agent behavior, live API, production ingestion, performance, other languages or other operating systems. This is a workflow tutorial, not a claim that any particular model commonly produces duplicates.
Find the real decoding boundary.
For your next experiment, trace where your application first turns text into an object. Try the authored duplicate there. Check that the failure remains visible to the caller and that no downstream write happens from rejected data. That real integration is separate work.
Optional review prompt: “Inspect this JSON ingestion code. Locate its first decode of raw response text. Identify where duplicate names could be discarded before validation. Propose an explicit rejection path without selecting a winning value.” This is a proposed prompt; we did not run it against a model.
Take the duplicate-key kit.
Practice ZIP · Complete exercise · Recorded results · Practice README · Review checklist
Original AI-generated conceptual portrait, visually reviewed. The artwork labels the cards as an authored example. Primary sources checked November 1, 2026.

