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

Explode aliases then recursively replace keys #2086

Open
tiawl opened this issue Jun 29, 2024 · 0 comments
Open

Explode aliases then recursively replace keys #2086

tiawl opened this issue Jun 29, 2024 · 0 comments

Comments

@tiawl
Copy link

tiawl commented Jun 29, 2024

Hi,

I am using the v4.44.1 version. I picked the blank template because I do not know if I am facing a normal behavior or a bug.

I have the following YAML file:

---
# john.yaml

someone: &someone
  name: John
  birthday: yesterday

list:
  - <<: *someone
    list:
      - <<: *someone

...

What I am trying to achieve is to:

  • explode aliases
  • then replace each keys recursively with dummy.

Here the commandline I use to achieve that:

yq -N 'explode(.) | (.. | key = "dummy") |= .' john.yaml

Here the result I am expecting:

dummy:
  dummy: John
  dummy: yesterday
dummy:
  - dummy: John
    dummy: yesterday
    dummy:
      - dummy: John
        dummy: yesterday

But it is giving me the following output:

dummy:
  dummy: John
  dummy: yesterday
dummy:
  - name: John
    birthday: yesterday
    list:
      - dummy: John
        dummy: yesterday

To get the expected behavior I have to use the following filter to "re-evaluate" the result of explode:

yq -N 'explode(.) | @yaml | @yamld | (.. | key = "dummy") |= .' john.yaml

Am I missing something ? Is this a normal behavior ?
Sorry if I am bothering with something really simple.
Thank you.

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

No branches or pull requests

1 participant