yq
yq copied to clipboard
Strange behaviour of YAML merge operator - creates an empty object
Describe the bug
I know, I know. Merge operator is no longer supported in YAML 1.2, though its use is still widespread.
What I can't wrap my head around is role of indentation when using <<:
.
Is there a 'correct' level of indent that is expected? Why is foo
in the example evaluated to an empty object?
Version of yq: 4.42.1 Operating system: linux Installed via: github release binary
Input Yaml
---
foo:
<<:
x: 1
y: 2
bar:
<<:
x: 1
y: 2
Command
yq e 'explode(.)' data.yml
Actual behavior
---
foo: {}
bar:
x: 1
y: 2
Expected behavior
---
foo:
x: 1
y: 2
bar:
x: 1
y: 2
Additional context N/A
Under foo
you're making x:1\ny:2
children of the merge anchor. The merge anchor format however is to provide a list of yaml aliases, which there are none, and so foo is effectively empty.
thanks, closing this.