SEO + AEO on AutopilotFrom the team at Stackmatix
The Growth Library

Reject Ambiguous JSON Product Facts Before Comparing an Answer

Inspect repeated JSON members before accepting a product fact, preserving object scope, parser choices and a complete ordered-pair detection fixture.

Inspect repeated JSON object members before treating structured product information as one unambiguous fact. An ordinary parser can silently retain one occurrence and discard another. A later answer may then look precise while depending on a parser choice that the source contract never established.

Preserve ordered member pairs, identify the object containing each repetition and separate legitimate reuse in different objects from repetition within one object. This is an input-fact ambiguity review, not an HTML JSON-LD embedding audit or a claim that every duplicate makes JSON grammatically invalid.

Use the specification's actual requirement

RFC 8259's object definition says names within an object SHOULD be unique. It explains that implementations can handle repeated names differently, including retaining a later value or reporting an error. Do not rewrite SHOULD as a universal grammar-level MUST.

Python's JSON documentation states that its default decoder accepts repeated names and retains the last name-value pair. It also exposes object_pairs_hook to alter that behavior. That is a documented Python choice, not a universal rule that the last member is the product's authoritative fact.

The relevant question is whether the inspected source and consumer contract establish which value governs. Without that evidence, a portable single-value claim remains unresolved.

Populate the contradictory source example

Assume a fictional product source contains the object {"mode":"standard","mode":"isolated"}. The two member names are the same within one object, while the values differ. These are synthetic product labels, not an actual service configuration.

Consumer PolicyResult for the Fictional ObjectWhat It Establishes
First occurrence retainedstandardA declared first-wins interpretation
Last occurrence retainedisolatedA declared last-wins interpretation
Repeated member rejectedNo accepted valueA declared uniqueness gate

All three are distinct consumer policies. A successful parse under one cannot establish that every downstream consumer sees the same mode. Nor does the source's authorization or correct URL resolve this internal conflict.

The field contract addresses omission, null and empty values. Those distinctions assume an identified property value; repeated competing occurrences create an earlier interpretation question.

Keep parent objects separate

The object {"A":{"mode":"standard"},"B":{"mode":"isolated"}} has one mode member inside A and one inside B. Those names do not conflict merely because they share the same spelling in the whole document.

A detector that counts every occurrence of mode would produce a false finding. Record object identity and member position before deciding which names repeat within the same scope.

Likewise, an array can contain several separate objects with the same field names. The object boundary, not the document-wide spelling count, determines the repetition being reviewed.

Inspect a bounded local detector

The following original Python example preserves each object's ordered member pairs instead of immediately collapsing them into a dictionary. It records conflicting names with their parent path and occurrence positions. It parses only the synthetic strings shown and performs no external action.

import json

class ObjectPairs(list):
    pass

def member_conflicts(text):
    root = json.loads(text, object_pairs_hook=ObjectPairs)
    conflicts = []

    def walk(value, path):
        if isinstance(value, ObjectPairs):
            seen = {}
            for position, (name, child) in enumerate(value, 1):
                if name in seen:
                    conflicts.append({
                        "object_path": path,
                        "name": name,
                        "first_member": seen[name],
                        "repeated_member": position
                    })
                else:
                    seen[name] = position
                walk(child, path + [{"member": name, "position": position}])
        elif isinstance(value, list):
            for index, child in enumerate(value):
                walk(child, path + [{"index": index}])

    walk(root, [])
    return conflicts

examples = {
    "duplicate": '{"mode":"standard","mode":"isolated"}',
    "nested_valid": '{"A":{"mode":"standard"},"B":{"mode":"isolated"}}',
    "nested_duplicate": '{"A":{"mode":"standard","mode":"isolated"}}',
    "array_duplicate": '[{"mode":"standard","mode":"isolated"}]',
    "escaped_duplicate": r'{"mode":1,"\u006dode":2}'
}
print(json.dumps({name: member_conflicts(text)
                  for name, text in examples.items()}, sort_keys=True))

ObjectPairs distinguishes object-member lists from actual JSON arrays. The path uses structured member positions or array indices, so a reviewer can identify a nested object without guessing from a flattened field name.

The hook also receives decoded member names. In the escaped fixture, the second spelling represents the same mode name, so it is detected as a repetition rather than treated as a separate field merely because its source characters differ.

Compare the complete fixture outcomes

FixtureConflict CountRelevant Parent
duplicate1Root object; positions 1 and 2
nested_valid0Different parent objects
nested_duplicate1A at root member position 1
array_duplicate1Array element 0
escaped_duplicate1Root object after member-name decoding

The detector reports member ambiguity. It is not a complete product schema validator, semantic equivalence engine or security boundary for arbitrarily large inputs. Malformed JSON still follows the parser's error behavior, and a conflict-free object can contain unsupported product claims.

Distinguish repetition from a false value

Repeated members can contain equal values. First-wins and last-wins consumers would then agree on that value, while a duplicate-rejecting consumer could still refuse the object. Record the interoperability defect without automatically declaring the shared value false.

An array containing the same scalar twice is another case: it has repeated values, not repeated object-member names. This detector intentionally does not reject that pattern. An application schema may separately prohibit it, but that rule needs its own evidence. Keeping these boundaries prevents a narrow member-ambiguity check from becoming an invented universal uniqueness validator.

Preserve the original before choosing a value

Once ordinary dictionary conversion discards earlier members, a downstream check cannot reconstruct them from the surviving value. Retain the authorized raw source or an appropriate evidence reference before a lossy parse.

Do not silently rewrite the source to whichever value matches the answer being reviewed. Ask the actual source owner to establish the intended fact and correction. Preserve the original ambiguity and the approved replacement as separate revisions.

The source worksheet should record the consumer policy if it is part of the real product contract. A known last-wins implementation can establish that consumer's result without making the contradictory source portable or well-maintained.

Separate this from framing and precedence

The JSON Lines guide checks complete physical record boundaries and application schema. One correctly framed line can still contain repeated object members. Framing success does not settle this interpretation.

Likewise, configuration precedence across a file, environment and command line is a different rule. Do not import that hierarchy into two occurrences within the same object unless the actual parser contract explicitly defines their handling.

Release an interpretable source fact

Retain the raw object, ordered occurrences, parent paths, consumer behavior, source-owner decision and corrected fact where available. Have another reviewer reproduce both the legitimate nested reuse and the repeated same-object finding.

A faithful answer can report a documented consumer's interpretation or identify the unresolved ambiguity. It should not turn one parser's silent choice into a universal product fact that the inspected source cannot unambiguously support.

Sources

Matt Pru

Co-founder and CEO of Stackmatix. Writing about growth, customer acquisition, and the decisions behind useful marketing. Connect on LinkedIn.

Developed with AI assistance under Matt's editorial direction. Our Editorial Approach