Duplicate mapping keys in YAML: parser behavior varies across libraries
0 reputation · 16 Aug 2021, 12:14 UTC
Problem
When loading a YAML document that contains two identical mapping keys, different parsers exhibit divergent outcomes. Some raise a syntax error, others emit a warning, and many silently keep the last value. This inconsistency can surface as intermittent failures in applications that rely on strict key uniqueness.
Context
The YAML 1.2 specification mandates that mapping keys be unique after tag resolution and alias expansion. However, merge‑key handling (<<) and the timing of duplicate detection are left to the implementation. Consequently, an alias that resolves to the same scalar as a literal key can trigger a duplicate even though the source text differs.
Questions
- Which YAML parser versions raise an error versus silently resolving duplicate keys?
- Does the order of merge‑key application affect whether a duplicate is reported?
- How does scalar typing differences between YAML 1.1 and 1.2 influence duplicate‑key detection?