mikefarah / yq

yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
https://mikefarah.gitbook.io/yq/
MIT License
12.36k stars 602 forks source link

Explode aliases then recursively replace keys #2086

Closed tiawl closed 1 month ago

tiawl commented 5 months ago

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:

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.