The <<:
operator in YAML is usable to import the contents of one mapping into another, similarly to the **
double-splat operator in Python or ...
object destructuring operator in JavaScript. For example,
foo:
a: b
<<:
c: d
e: f
is equivalent to
foo:
a: b
c: d
e: f
This is useful when used along with node anchors to include some common default properties in many objects, as illustrated in, for example, the Learn YAML in Y minutes tutorial:
# Anchors can be used to duplicate/inherit properties base: &base name: Everyone has same name foo: &foo <<: *base age: 10 bar: &bar <<: *base age: 20
However, I am confused about where this syntax comes from or why it works. CTRL + Fing the YAML specification for <<
reveals that it doesn't appear anywhere in the specification. Yet it's supported by, at the very least, PyYAML and Online YAML Parser.
What is this syntax, and how come it doesn't seem to appear in the specification?
<<:
operator it is a specific key<<
in a key value pair. The:
is the normal key-value separator. – Trogon