FAILURE MAP
← Case archive

FA-176 / Serialization / Open access

A repeated JSON key silently overwrites a value · case 01

Conflicting object members collapse to one value, hiding an ambiguous source document.

Verified by executionVariant 1 · 9 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The decoder materializes a dictionary before validating the original member pairs.

VERIFIED REPAIR

Reject duplicate decoded member names within every individual object before constructing its dictionary.

Unsuccessful approach: Searching raw key text across the whole document rejects legitimate reuse in separate objects and misses escaped equivalent names.

Case contract

Decode any valid JSON value into an {ok, value} envelope. Reject syntax errors and duplicate decoded keys at any object depth with {ok: False}; key reuse in different objects is allowed.

Why this case matters

A strict configuration or signed-message consumer must distinguish repeated members from valid reuse in separate scopes. This contract is stricter than Python's default JSON decoder.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re
def reject_constant(value):
    raise ValueError('non-JSON numeric constant')
N = 1
observations = []
def solve(text):
    try:
        return {'ok': True, 'value': json.loads(text, parse_constant=reject_constant)}
    except ValueError:
        return {'ok': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('duplicate top-level member', solve('{"a":' + str(N) + ',"a":0}'), {'ok': False})
check('duplicate nested member', solve('{"outer":{"a":1,"a":2}}'), {'ok': False})
check('same name in separate scopes', solve('{"a":' + str(N) + ',"child":{"a":2}}'), {'ok': True, 'value': {'a': N, 'child': {'a': 2}}})
check('escaped name equals literal name', solve(r'{"a":1,"\u0061":2}'), {'ok': False})
check('same member in separate array objects', solve(json.dumps([{'a': i} for i in range(N + 1)])), {'ok': True, 'value': [{'a': i} for i in range(N + 1)]})
check('empty object', solve('{}'), {'ok': True, 'value': {}})
check('valid null differs from decode failure', solve('null'), {'ok': True, 'value': None})
check('malformed syntax', solve('{"a":}'), {'ok': False})
check('non-JSON numeric constant rejected', solve('NaN'), {'ok': False})
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
duplicate top-level member{'ok': True, 'value': {'a': 0}}{'ok': False}Failed
duplicate nested member{'ok': True, 'value': {'outer': {'a': 2}}}{'ok': False}Failed
same name in separate scopes{'ok': True, 'value': {'a': 1, 'child': {'a': 2}}}{'ok': True, 'value': {'a': 1, 'child': {'a': 2}}}Passed
escaped name equals literal name{'ok': True, 'value': {'a': 2}}{'ok': False}Failed
same member in separate array objects{'ok': True, 'value': [{'a': 0}, {'a': 1}]}{'ok': True, 'value': [{'a': 0}, {'a': 1}]}Passed
empty object{'ok': True, 'value': {}}{'ok': True, 'value': {}}Passed
valid null differs from decode failure{'ok': True, 'value': None}{'ok': True, 'value': None}Passed
malformed syntax{'ok': False}{'ok': False}Passed
non-JSON numeric constant rejected{'ok': False}{'ok': False}Passed

SHA-256 / a62ccacb2feefff838cd7d64a865e4d0d953bcfa4bdbb48b28a9de086ec350a5

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re
def reject_constant(value):
    raise ValueError('non-JSON numeric constant')
N = 1
observations = []
def solve(text):
    keys = re.findall(r'"([^"\\]*)"\s*:', text)
    if len(keys) != len(set(keys)):
        return {'ok': False}
    try:
        return {'ok': True, 'value': json.loads(text, parse_constant=reject_constant)}
    except ValueError:
        return {'ok': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('duplicate top-level member', solve('{"a":' + str(N) + ',"a":0}'), {'ok': False})
check('duplicate nested member', solve('{"outer":{"a":1,"a":2}}'), {'ok': False})
check('same name in separate scopes', solve('{"a":' + str(N) + ',"child":{"a":2}}'), {'ok': True, 'value': {'a': N, 'child': {'a': 2}}})
check('escaped name equals literal name', solve(r'{"a":1,"\u0061":2}'), {'ok': False})
check('same member in separate array objects', solve(json.dumps([{'a': i} for i in range(N + 1)])), {'ok': True, 'value': [{'a': i} for i in range(N + 1)]})
check('empty object', solve('{}'), {'ok': True, 'value': {}})
check('valid null differs from decode failure', solve('null'), {'ok': True, 'value': None})
check('malformed syntax', solve('{"a":}'), {'ok': False})
check('non-JSON numeric constant rejected', solve('NaN'), {'ok': False})
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
duplicate top-level member{'ok': False}{'ok': False}Passed
duplicate nested member{'ok': False}{'ok': False}Passed
same name in separate scopes{'ok': False}{'ok': True, 'value': {'a': 1, 'child': {'a': 2}}}Failed
escaped name equals literal name{'ok': True, 'value': {'a': 2}}{'ok': False}Failed
same member in separate array objects{'ok': False}{'ok': True, 'value': [{'a': 0}, {'a': 1}]}Failed
empty object{'ok': True, 'value': {}}{'ok': True, 'value': {}}Passed
valid null differs from decode failure{'ok': True, 'value': None}{'ok': True, 'value': None}Passed
malformed syntax{'ok': False}{'ok': False}Passed
non-JSON numeric constant rejected{'ok': False}{'ok': False}Passed

SHA-256 / 4ec55786b9975aaf8df69e2e0550587b9973222af9424640aa62ccfdf9cfce12

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import re
def reject_constant(value):
    raise ValueError('non-JSON numeric constant')
N = 1
observations = []
def solve(text):
    def object_from_pairs(pairs):
        result = {}
        for key, value in pairs:
            if key in result:
                raise ValueError('duplicate member')
            result[key] = value
        return result
    try:
        return {'ok': True, 'value': json.loads(text, object_pairs_hook=object_from_pairs, parse_constant=reject_constant)}
    except ValueError:
        return {'ok': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('duplicate top-level member', solve('{"a":' + str(N) + ',"a":0}'), {'ok': False})
check('duplicate nested member', solve('{"outer":{"a":1,"a":2}}'), {'ok': False})
check('same name in separate scopes', solve('{"a":' + str(N) + ',"child":{"a":2}}'), {'ok': True, 'value': {'a': N, 'child': {'a': 2}}})
check('escaped name equals literal name', solve(r'{"a":1,"\u0061":2}'), {'ok': False})
check('same member in separate array objects', solve(json.dumps([{'a': i} for i in range(N + 1)])), {'ok': True, 'value': [{'a': i} for i in range(N + 1)]})
check('empty object', solve('{}'), {'ok': True, 'value': {}})
check('valid null differs from decode failure', solve('null'), {'ok': True, 'value': None})
check('malformed syntax', solve('{"a":}'), {'ok': False})
check('non-JSON numeric constant rejected', solve('NaN'), {'ok': False})
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
duplicate top-level member{'ok': False}{'ok': False}Passed
duplicate nested member{'ok': False}{'ok': False}Passed
same name in separate scopes{'ok': True, 'value': {'a': 1, 'child': {'a': 2}}}{'ok': True, 'value': {'a': 1, 'child': {'a': 2}}}Passed
escaped name equals literal name{'ok': False}{'ok': False}Passed
same member in separate array objects{'ok': True, 'value': [{'a': 0}, {'a': 1}]}{'ok': True, 'value': [{'a': 0}, {'a': 1}]}Passed
empty object{'ok': True, 'value': {}}{'ok': True, 'value': {}}Passed
valid null differs from decode failure{'ok': True, 'value': None}{'ok': True, 'value': None}Passed
malformed syntax{'ok': False}{'ok': False}Passed
non-JSON numeric constant rejected{'ok': False}{'ok': False}Passed

SHA-256 / baab9d35afaa65beaa1eae3396bbdee3b05232ecd6515bcdef4b8e03140ebdae

Verification & scope

This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:36:51.012628+00:00.

Case digest / e767858ce1d6fb2c600bd69076fdbad94d6afb2971f2dc99382968dbb1809950