Site icon JD Bots

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

Syntax

key: true
other_key: false

YAML 1.2’s core schema reads true, True, TRUE, false, False and FALSE as booleans: see Tag Resolution 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.yml

open: true
delivery: false

Step 2: Read a Value

Terminal

yq '.open' shop.yml

Output

true

Step 3: Check the Type

Terminal

yq '.open | type' shop.yml

Output

!!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

Exit mobile version