Parent
Parent simply returns the parent nodes of the matching nodes.
Simple example
Given a sample.yml file of:
a:
nested: catthen
yq '.a.nested | parent' sample.ymlwill output
nested: catParent of nested matches
Given a sample.yml file of:
a:
fruit: apple
name: bob
b:
fruit: banana
name: samthen
will output
Get parent attribute
Given a sample.yml file of:
then
will output
Get parents
Match all parents
Given a sample.yml file of:
then
will output
Get the top (root) parent
Use negative numbers to get the top parents. You can think of this as indexing into the 'parents' array above
Given a sample.yml file of:
then
will output
Root
Alias for parent(-1), returns the top level parent. This is usually the document node.
Given a sample.yml file of:
then
will output
N-th parent
You can optionally supply the number of levels to go up for the parent, the default being 1.
Given a sample.yml file of:
then
will output
N-th parent - another level
Given a sample.yml file of:
then
will output
N-th negative
Similarly, use negative numbers to index backwards from the parents array
Given a sample.yml file of:
then
will output
No parent
Given a sample.yml file of:
then
will output
Last updated