yq/operators/parent.md
2021-11-26 09:50:45 +11:00

620 B

Parent

Parent simply returns the parent nodes of the matching nodes.

Simple example

Given a sample.yml file of:

a:
  nested: cat

then

yq eval '.a.nested | parent' sample.yml

will output

nested: cat

Parent of nested matches

Given a sample.yml file of:

a:
  fruit: apple
  name: bob
b:
  fruit: banana
  name: sam

then

yq eval '.. | select(. == "banana") | parent' sample.yml

will output

fruit: banana
name: sam

No parent

Given a sample.yml file of:

{}

then

yq eval 'parent' sample.yml

will output