Let me collect all relevant places in the specs.
Full disclosure: This is the first time I'm going through them looking
for something formal.
>
http://www.yaml.org/spec/1.2/spec.html
> 1.3 Relation to JSON JSON's RFC4627 requires that mappings keys
> merely “SHOULD” be unique, while YAML insists they “MUST” be.
The section is descriptive rather than prescriptive I think, but the
intent of the spec makers is pretty clearly stated here.
> 3.1.2 Load Constructing Native Data Structures Construction must be
> based only on the information available in the representation, and
> not on additional serialization or presentation details such as [...]
> mapping key order, [...]
If duplicate keys are ignored, the selection of which of two conflicting
key-value pairs will get included implies a dependency on mapping key
order. (You could code something to make the selectin random, but
throwing an error might be easier.)
This is a very implicit conclusion, I doubt that the authors wanted to
enforce key uniqueness with just this paragraph :-)
> 3.2.1. Representation Graph Mapping nodes are somewhat tricky
> because their keys are unordered and must be unique.
Looks like another reference to a uniqueness requirement somewhere in
the spec.
> 3.2.1.1. Nodes A YAML node represents a single native data
> structure.
I.e. the node is the consolidated YAML information for a native data
structure. Regardless of origin (multiple key-value pairs, merging [1],
whatever).
[1] Merging is actually an exception, see the end of this analysis.
> 3.2.1.1. Nodes Mapping The content of a mapping node is an unordered
> set of key: value node pairs, with the restriction that each of the
> keys is unique.
So all the consolidated YAML information pertaining to a Java Map must
not contain multiple keys.
> 3.2.1.3. Node Comparison
> Since YAML mappings require key uniqueness, representations must
> include a mechanism for testing the equality of nodes. This is
> non-trivial since YAML allows various ways to format scalar content.
> For example, the integer eleven can be written as “0o13” (octal) or
> “0xB” (hexadecimal). If both notations are used as keys in the same
> mapping, only a YAML processor which recognizes integer formats would
> correctly flag the duplicate key as an error.
The last partial sentence can be read as "YAML processors do not need to
recognize duplicates if that's due to representational differences", but
it can also be read as "YAML processors need to canonicalize integer
keys so they can do proper duplicated detection".
Given that duplicate keys are excluded prescriptively, and in multiple
location descriptively, I prefer the latter interpretation.
>
http://yaml.org/type/merge.html
Now here the rules are quite different:
> The “<<” merge key is used to indicate that all the keys of one or
> more specified maps should be inserted into the current map. If the
> value associated with the key is a single mapping node, each of its
> key/value pairs is inserted into the current mapping, unless the key
> already exists in it.
So a *merge* does indeed have a dependency on YAML order: earlier
key:value pairs override later ones.
I hope this helps with decision-making ;-)
Regards
Jo