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
trueandfalse: 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 in the YAML 1.2.2 specification.
Prerequisites
- yq, to check the YAML. Install it from yq’s install instructions.
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
| Mistake | What happens | Do this instead |
|---|---|---|
Putting it in quotes: open: "true" | It’s text: yq '.open | type' shop.yml prints !!str | Leave out the quotes |
Writing yes for true | In YAML 1.2, yes is text too: yq '.open | type' shop.yml prints !!str | Write 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
- Tag Resolution (YAML 1.2.2 specification)
- Tag (yq documentation)
