vmware-labs / yaml-jsonpath

JSONPath implementation for the gopkg.in/yaml.v3 node API
Other
49 stars 12 forks source link

Follow alias nodes #52

Open sergeyrud-stripe opened 1 year ago

sergeyrud-stripe commented 1 year ago

Is your feature request related to a problem? Please describe.

Is it possible to opt in to following aliases when looking for nodes? For instance, if I have the following path $.production.foo and YAML structure

default: &default
  foo: bar

production:
  <<: *default

I’d like to get the bar node without changing the path from $.production.foo to $.default.foo.

Describe the solution you'd like

API could possibly be as follows:

const data = `
default: &default
  foo: bar

production:
  <<: *default
`
var node yaml.Node
yaml.Unmarshal([]byte(data), &node)
p, _ := yamlpath.NewPath("$.production.foo")
p.FollowAliases(true) // new func that toggles this behaviour.
nodes, _ := p.Find(&node)

Describe alternatives you've considered

No response

Additional context

No response