Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behaviour of YAML merge operator - creates an empty object #1984

Open
pcppcp opened this issue Mar 20, 2024 · 1 comment
Open

Strange behaviour of YAML merge operator - creates an empty object #1984

pcppcp opened this issue Mar 20, 2024 · 1 comment
Labels

Comments

@pcppcp
Copy link

pcppcp commented Mar 20, 2024

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

@mikefarah
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants