Closed
Description
Discussed in #1937
Originally posted by qaisjp February 6, 2024
I have the following YAML:
foo: &foo
hello: world
bar:
<<: *foo
And would like to compute the following values based on the "parent" of each object
foo: &foo
parent: null
bar:
parent: foo # bar inherits from "foo", so the value of bar.parent should be "foo"
I've tried the following filters, but can't seem to figure it out!
filter attempt 1
the following queries:
with_entries(.value |= {
"parent": . | alias
})
with_entries(.value |= {
"parent": alias
})
produces
foo: &foo
parent: ""
bar:
parent: "" # expected "foo"
filter attempt 2
with_entries(.value |= {
"parent": .["<<"]
})
produces
foo: &foo
parent: null
bar:
parent: null
filter attempt 3
with_entries(.value |= {
"parent": (.["<<"] | alias)
})
produces
foo: &foo
parent: "null"
bar:
parent: "null"
Note that it works fine with anchors
with_entries(.value |= {
"anchor_name": . | anchor
})
produces
foo: &foo
anchor_name: foo
bar:
anchor_name: ""
<<: *
is parsed correctly
When I just pipe my yaml through with the .
filter, I get
foo: &foo
hello: world
bar:
!!merge <<: *foo
Which is correct — according to the docs it says:
yq
supports merge aliases (like<<: *blah
) however this is no longer in the standard yaml spec (1.2) and soyq
will automatically add the!!merge
tag to these nodes as it is effectively a custom tag.
(also mentioned at #680 (comment))
but why can't I read the merge alias at .["<<"]
?
Any pointers? 🙁 Thanks!
Metadata
Assignees
Labels
No labels
Activity