yq icon indicating copy to clipboard operation
yq copied to clipboard

Strange behaviour of YAML merge operator - creates an empty object

Open pcppcp opened this issue 11 months ago • 1 comments

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

pcppcp avatar Mar 20 '24 08:03 pcppcp

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.

mikefarah avatar Mar 24 '24 00:03 mikefarah

thanks, closing this.

pcppcp avatar May 27 '24 12:05 pcppcp