yq icon indicating copy to clipboard operation
yq copied to clipboard

Explode operator with nested anchors

Open jtyr opened this issue 2 years ago • 2 comments

I have a document that is using nested YAML anchors. I'm using the explode() operator to resolve the anchors but if I have multiple nested anchors, it seems to only resolve the first level of of the nested anchors.

The following command:

cat <<END > aaa.yaml
aaa:
  - &first
    aaa: bbb
  - &second
    <<: *first
    ccc: ddd
  - <<: *second
    eee: fff
END
yq '.aaa[2] | explode(.)' aaa.yaml

produces the following output:

!!merge <<:
  aaa: bbb
ccc: ddd
eee: fff

where I would expect it to produce this:

aaa: bbb
ccc: ddd
eee: fff

I'm running yq in the version 4.30.6 on Arch Linux.

jtyr avatar Jan 19 '23 14:01 jtyr

Hmm not sure why that's not working, need to look into it. As a workaround, if you run explode first then it works:

yq 'explode(.) | .aaa[2]' aaa.yaml

mikefarah avatar Jan 23 '23 00:01 mikefarah