Skip to main content
0 reactions

How to Write true and false in YAML

Featured card for How to Write true and false in YAML: a shop.yml file with open: true and delivery: false, a yq command that prints the type of .open as !!bool, and the notes No quotes and yes is text, not true.
How to Write true and false in YAML

YAML reads the words true and false, without quotes, as the two boolean values. Use them for settings that are either on or off.

Every command and output on this page is real, run with yq 4.54.3 on macOS.

Syntax

SyntaxYAML
key: true
other_key: false
  • true and false: the two booleans, without quotes. Lowercase is the usual way to write them.
  • With quotes, "true" is text, not a boolean.

YAML 1.2’s core schema reads true, True, TRUE, false, False and FALSE as booleans: see Tag Resolution (opens in a new tab) in the YAML 1.2.2 specification.

Prerequisites

The Example

A shop’s settings, in a file named shop.yml: it’s open, and it doesn’t deliver.

Step 1: Write the YAML

shop.ymlYAML
open: true
delivery: false

Step 2: Read a Value

TerminalBash
yq '.open' shop.yml
OutputPlain text
true

Step 3: Check the Type

TerminalBash
yq '.open | type' shop.yml
OutputPlain text
!!bool

type prints what kind of value it is: !!bool is a boolean.

Common Mistakes

MistakeWhat happensDo this instead
Putting it in quotes: open: "true"It’s text: yq '.open | type' shop.yml prints !!strLeave out the quotes
Writing yes for trueIn YAML 1.2, yes is text too: yq '.open | type' shop.yml prints !!strWrite true

FAQ

What does !!bool mean?

It’s YAML’s tag for a boolean. yq’s type prints a value’s tag, such as !!str for text.

Conclusion

Write true and false without quotes for settings that are on or off. Quoted, or written as yes, they’re text.

Additional Resources

0 comments