Value Parsing
How values are parsed from the CLI to commands that create/update yaml (e.g. new/write).
yq
attempts to parse values intelligently, e.g. when a number is passed it - it will assume it's a number as opposed to a string. yq
will not alter the representation of what you give. So if you pass '03.0' in, it will assume it's a number and keep the value formatted as it was passed in, that is '03.0'.
The --tag
flag can be used to override the tag type to force particular tags.
Default behavior
Integers
Given
results in
Given a formatted number
results in
yq
keeps the number formatted as it was passed in.
Float
Given
results in
Note that quoting the number does not make a difference.
Given a formatted decimal number
results in
yq
keeps the number formatted as it was passed in
Booleans
Note that yq
supports yaml spec 1.2 - which means the values yes/no are no longer parsed as booleans, but as strings see https://yaml.org/spec/1.2/spec.html and https://github.com/go-yaml/yaml/tree/v3 for more information.
results in
Nulls
results in
results in
results in
Strings
results in
results in
Using the tag flag to cast
Previous versions of yq required double quoting to force values to be strings, this no longer works - instead use the --tag flag.
Casting booleans
results in
Casting nulls
results in
Custom types
results in
The style flag
The --style
flag can be used to specify the quote or block style of the node value. Valid values are
single
double
folded
flow
literal
tagged
For example, given:
Single
Double
Folded:
Folded single line:
Flow:
Flow single line:
Literal
Literal single line
Tagged
Always show the tag, note - you must also pass in --tag='!!str'
Tagged single line
Last updated