What is the << (double left arrow) syntax in YAML called, and where's it specced?

It is called the Merge Key Language-Independent Type for YAML version 1.1. and specced here

It is something that parsers can optionally support, it is essentially an interpretation of the key-value pair with the special key <<, where the value is either a mapping (usually indicated via an alias as in the spec, and although that doesn't seem to be required, it makes little sense not to use an alias) or a list of mappings (i.e. aliases of mappings), and gets interpreted in a special way.


To add on to other answers:

IMO, the example from "Learn yaml in Y Minutes" is incomplete because it doesn't show what happens when the keys are the same. For example:

base: &base
    name: Everyone has same name
    age: 5

foo: &foo
    <<: *base

bar: &bar
    <<: *base
    age: 20

For the bottom two items yields:

foo: 
    name: Everyone has same name
    age: 5

bar:
    name: Everyone has same name
    age: 20

bar overrides the age while foo does not. According to the spec the entries of the object merging in have a lower priority than those on the object receiving them.

Tags:

Yaml