yq/pkg/yqlib/doc/operators/parent.md
2022-02-06 14:39:46 +11:00

753 B

Parent

Parent simply returns the parent nodes of the matching nodes.

{% hint style="warning" %} Note that versions prior to 4.18 require the 'eval/e' command to be specified.

yq e <exp> <file> {% endhint %}

Simple example

Given a sample.yml file of:

a:
  nested: cat

then

yq '.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 '.. | select(. == "banana") | parent' sample.yml

will output

fruit: banana
name: sam

No parent

Given a sample.yml file of:

{}

then

yq 'parent' sample.yml

will output