y
y
yq
Search…
Tag
The tag operator can be used to get or set the tag of nodes (e.g. !!str, !!int, !!bool).

Get tag

Given a sample.yml file of:
1
a: cat
2
b: 5
3
c: 3.2
4
e: true
5
f: []
Copied!
then
1
yq eval '.. | tag' sample.yml
Copied!
will output
1
!!map
2
!!str
3
!!int
4
!!float
5
!!bool
6
!!seq
Copied!

Set custom tag

Given a sample.yml file of:
1
a: str
Copied!
then
1
yq eval '.a tag = "!!mikefarah"' sample.yml
Copied!
will output
1
a: !!mikefarah str
Copied!

Find numbers and convert them to strings

Given a sample.yml file of:
1
a: cat
2
b: 5
3
c: 3.2
4
e: true
Copied!
then
1
yq eval '(.. | select(tag == "!!int")) tag= "!!str"' sample.yml
Copied!
will output
1
a: cat
2
b: "5"
3
c: 3.2
4
e: true
Copied!