y
y
yq
Search…
Parent
Parent simply returns the parent nodes of the matching nodes.

Simple example

Given a sample.yml file of:
1
a:
2
nested: cat
Copied!
then
1
yq eval '.a.nested | parent' sample.yml
Copied!
will output
1
nested: cat
Copied!

Parent of nested matches

Given a sample.yml file of:
1
a:
2
fruit: apple
3
name: bob
4
b:
5
fruit: banana
6
name: sam
Copied!
then
1
yq eval '.. | select(. == "banana") | parent' sample.yml
Copied!
will output
1
fruit: banana
2
name: sam
Copied!

No parent

Given a sample.yml file of:
1
{}
Copied!
then
1
yq eval 'parent' sample.yml
Copied!
will output
1
Copied!
Last modified 1mo ago