BudiBadu Logo
Samplebadu

YAML by Example: Boolean Values

1.2

True and false representation. Multiple ways to express booleans.

Code

# Standard boolean values (recommended)
enabled: true
disabled: false

# Alternative representations (YAML 1.1)
legacy_true: yes
legacy_false: no

switch_on: on
switch_off: off

# Case variations (all valid but use lowercase)
uppercase: TRUE
mixedcase: False

# As strings (when you need literal text)
permission: "yes"  # This is a string, not boolean
answer: "false"    # This is a string, not boolean

Explanation

The standard way to write booleans in YAML is lowercase true and false. YAML 1.1 also recognized yes/no and on/off, and many parsers still accept these for backward compatibility. While case variations work, stick to lowercase for consistency.

If you need the literal word "yes" or "true" as a string value, use quotes. Without quotes, these words become boolean values. This is a common source of confusion when dealing with user input or survey responses.

Code Breakdown

2-3
Use true and false as the standard boolean format.
15-16
Quotes prevent these from being interpreted as booleans.