Guide
YAML booleans: why yes, no, on, and off depend on the version
Prevent words such as yes, no, on, and off from changing between strings and booleans across YAML parsers and versions.
by Tools in a Tab · Published on · Updated
Short answer
In YAML 1.2 Core, true and false are booleans; True, TRUE, False, and
FALSE are also recognized. Unquoted yes, no, on, and off are strings.
YAML 1.1 recognized
those same words as booleans. If you do not control the parser version and
schema, quote any word that must remain a string.
Use the YAML to JSON converter to check the types with YAML 1.2 Core, or jump to the compatibility checklist.
The same text can produce different types
Consider this configuration:
answer: yes
switch: off
publish: true
Under YAML 1.1 resolution, yes and off can become true and false. Under
the YAML 1.2 Core schema, this example produces exactly:
{
"answer": "yes",
"switch": "off",
"publish": true
}
The YAML 1.2.2 Core resolution rules
recognize six spellings: true, True, TRUE, false, False, and FALSE.
Mixed forms such as tRuE remain strings. Lowercase true and false are the
portable choice and also match JSON syntax. The historical
YAML 1.1 boolean type documents y, n,
yes, no, on, and off, including case variants.
Write unambiguous values
Use explicit booleans for logical data and quotes for text:
answer: 'yes'
switch: 'off'
publish: true
This matters for country codes, form responses, state names, and configuration values. Turning a string into a boolean can alter a comparison, a table column, or an API request even though the YAML does not look broken.
Inspect the actual conversion
Paste a small case into the YAML to JSON converter
and inspect both value and type: strings have quotes in JSON, while booleans do
not. The tool uses YAML 1.2 Core and rejects a %YAML 1.1 directive. It does
not simulate a legacy parser, and simply changing that directive does not
preserve legacy types. The decisive test is always the parser that will run
your application.
When converting back with JSON to YAML, you start from explicit JSON types. Still review strings that might look special to the final consumer.
Checklist
- Find out whether the system expects YAML 1.1 or 1.2 and which schema it uses.
- Write booleans as
trueorfalse. - Quote
yes,no,on, andoffwhen they are text. - Convert a sample and compare types, not just appearance.
Quotes are not noise here: they document that the value must stay text in every environment.