Skip to content
YAML

Tags

Explicit type tags for custom resolution.

By EZ4Code Team
tagtypecustom

Code

# Built-in tags force a specific type
not_a_string: !!str 123
not_a_date: !!str 2024-01-01
explicit_int: !!int "42"
explicit_bool: !!bool "yes"

# Local custom tags
shape: !circle
  radius: 5
color: !rgb "ff00ff"

Explanation

Tags prefixed with !! force a built-in type resolution, overriding the schema's default guess so that 123 stays a string. Single-bang ! tags are application-specific and let custom constructors decode domain types. Defining custom tags requires a parser hook such as PyYAML's add_constructor.

More YAML Snippets