HELLO, I’M SERHAT AND THIS IS MY FANCY TITLE.

Boolean Type Words in YAML

YAML is a widely used data serialization language. In any software development project, or a random dev-ops task you can come across with YAML. For example Ruby on Rails uses YAML for fixtures, configuration files and localization. CI/CD tools such as CircleCI and Travis also use YAML for configuration. If you ever experienced a strange behaviour with YAML, you may have used the reserved words of YAML. YAML reserves some words such as 'yes', 'no', 'y', 'n', 'off', 'on', etc. for boolean type. For example:

yes:
    turkish: evet
    german: ja
    english: yes
no:
    turkish: hayır
    german: nein
    english: no

will be interpreted as:

true:
    turkish: evet
    english: true
false:
    turkish: hayır
    english: false

actually YAML has a long list of reserved words for boolean type:

y|Y|yes|Yes|YES|n|N|no|No|NO
|true|True|TRUE|false|False|FALSE
|on|On|ON|off|Off|OFF

In order to prevent YAML for interpreting these words as boolean, you need to wrap them with single or double quotes like this:

'yes':
    'turkish': 'evet'
    'german': 'ja'
    'english': 'yes'
'no':
    'turkish': 'hayır'
    'german': 'nein'
    'english': 'no'

YAML also interprets some words to null, so wrap them inside quotes too:

~ # (canonical)
|null|Null|NULL # (English)
| # (Empty)

Cheers.

Date:
Categories: tech, ruby, ruby on rails

Share this post!


Blog Comments powered by Disqus.