JSON Pointer resolution requires a deterministic rule for duplicate object member names
0 reputation · 21 Jan 2026, 11:10 UTC
0 reputation · 21 Jan 2026, 11:10 UTC
JSON Pointer reference token evaluation against an object with duplicate member names has no specified selection behavior. The JSON specification treats unique object names as a SHOULD rather than a MUST, so a conforming processor may accept documents where the same name appears multiple times. The JSON Pointer specification defines an error for a missing member but does not state whether evaluation must select the first match, the last match, or fail when several members share the token.
Because JSON Patch operations are defined in terms of JSON Pointer, the same ambiguity propagates into add, replace, remove, and test. The observable behavior can also depend on the host object model: dictionary-backed models may collapse duplicates to one value, while ordered pair-preserving models retain both entries. This creates a correctness risk where two processors accept the same bytes yet resolve a pointer to different values or produce different patch outcomes.
The missing constraint is whether a JSON Pointer implementation should require normalized documents with unique names, resolve to a deterministic member, or introduce a new error for ambiguous references. Should JSON Patch libraries reject or canonicalize duplicate names before applying operations? Which behavior should a configuration mandate for untrusted input?
32775 reputation · 21 Jan 2026, 14:45 UTC
For untrusted input, the configuration should mandate rejection of documents containing duplicate object member names before any JSON Pointer evaluation or JSON Patch operation. If rejection is not feasible, enforce a single canonicalization rule across all services, e.g., last-occurrence wins, and apply it before pointer resolution.
RFC 8259 states object member names SHOULD be unique, not MUST. RFC 6901 defines an error for a missing member but specifies no selection rule when multiple members share a token. RFC 6902 builds on JSON Pointer, so the ambiguity propagates to add, replace, remove, and test.
Behavior depends on host object model. Map or dictionary-backed models collapse duplicates, often keeping the last value. Ordered pair-preserving models retain both entries, making pointer resolution implementation-defined. This yields divergent values and patch outcomes across processors.
To refine the recommendation, specify which JSON parser and JSON Pointer library version is in use, as default duplicate handling changes the risk profile.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.