y
y
yq
Search…
Recursive Descent (Glob)
This operator recursively matches (or globs) all children nodes given of a particular element, including that node itself. This is most often used to apply a filter recursively against all matches. It can be used in either the

match values form ..

This will, like the jq equivalent, recursively match all value nodes. Use it to find/manipulate particular values.
For instance to set the style of all value nodes in a yaml doc, excluding map keys:
1
yq eval '.. style= "flow"' file.yaml
Copied!

match values and map keys form ...

The also includes map keys in the results set. This is particularly useful in YAML as unlike JSON, map keys can have their own styling, tags and use anchors and aliases.
For instance to set the style of all nodes in a yaml doc, including the map keys:
1
yq eval '... style= "flow"' file.yaml
Copied!

Recurse map (values only)

Given a sample.yml file of:
1
a: frog
Copied!
then
1
yq eval '..' sample.yml
Copied!
will output
1
a: frog
2
frog
Copied!

Recursively find nodes with keys

Note that this example has wrapped the expression in [] to show that there are two matches returned. You do not have to wrap in [] in your path expression.
Given a sample.yml file of:
1
a:
2
name: frog
3
b:
4
name: blog
5
age: 12
Copied!
then
1
yq eval '[.. | select(has("name"))]' sample.yml
Copied!
will output
1
- name: frog
2
b:
3
name: blog
4
age: 12
5
- name: blog
6
age: 12
Copied!

Recursively find nodes with values

Given a sample.yml file of:
1
a:
2
nameA: frog
3
b:
4
nameB: frog
5
age: 12
Copied!
then
1
yq eval '.. | select(. == "frog")' sample.yml
Copied!
will output
1
frog
2
frog
Copied!

Recurse map (values and keys)

Note that the map key appears in the results
Given a sample.yml file of:
1
a: frog
Copied!
then
1
yq eval '...' sample.yml
Copied!
will output
1
a: frog
2
a
3
frog
Copied!

Aliases are not traversed

Given a sample.yml file of:
1
a: &cat
2
c: frog
3
b: *cat
Copied!
then
1
yq eval '[..]' sample.yml
Copied!
will output
1
- a: &cat
2
c: frog
3
b: *cat
4
- &cat
5
c: frog
6
- frog
7
- *cat
Copied!

Merge docs are not traversed

Given a sample.yml file of:
1
foo: &foo
2
a: foo_a
3
thing: foo_thing
4
c: foo_c
5
bar: &bar
6
b: bar_b
7
thing: bar_thing
8
c: bar_c
9
foobarList:
10
b: foobarList_b
11
!!merge <<:
12
- *foo
13
- *bar
14
c: foobarList_c
15
foobar:
16
c: foobar_c
17
!!merge <<: *foo
18
thing: foobar_thing
Copied!
then
1
yq eval '.foobar | [..]' sample.yml
Copied!
will output
1
- c: foobar_c
2
!!merge <<: *foo
3
thing: foobar_thing
4
- foobar_c
5
- *foo
6
- foobar_thing
Copied!
Last modified 2mo ago