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:
a: cat
b: 5
c: 3.2
e: true
f: []then
yq '.. | tag' sample.ymlwill output
!!map
!!str
!!int
!!float
!!bool
!!seqtype is an alias for tag
Given a sample.yml file of:
a: cat
b: 5
c: 3.2
e: true
f: []then
yq '.. | type' sample.ymlwill output
!!map
!!str
!!int
!!float
!!bool
!!seqSet custom tag
Given a sample.yml file of:
a: strthen
yq '.a tag = "!!mikefarah"' sample.ymlwill output
a: !!mikefarah strFind numbers and convert them to strings
Given a sample.yml file of:
a: cat
b: 5
c: 3.2
e: truethen
yq '(.. | select(tag == "!!int")) tag= "!!str"' sample.ymlwill output
a: cat
b: "5"
c: 3.2
e: trueLast updated
Was this helpful?