YAML is a human-readable data serialization standard that can be used to represent different data types. In this shot, we learn to represent some of the most common data types in
Scalars are the simplest data type in
YAML and can represent basic types, including boolean, integers, and floating-point numbers. The following basic data types are supported by
Here is an example of how to represent a string, an integer, a floating-point number, and a boolean value in
string: "Hello" integer: 123 float: 12.345 boolean: No
As we can see, the format for each data type is very similar. To represent a string in
YAML, we use a single quote (
') or a double quote (
") and the actual string value within these quotes. We use the standard numeric literals for integers and floating-point numbers. Boolean values can be represented in
YAML using the keywords like
YAML can autodetect types. However, it is often necessary to explicitly specify the type using a tag. To force a type, we can prefix the type with a
!! symbol. Here's an example:
age: !!float 23 married: !!str true binary: !!int 0b101010 hexadecimal: !!int 0x1C7A name: !!str "James"
Here is the table showing a list of tags supported in
YAML along with its description:
Denotes a boolean value
Denotes a integer value
Denotes a floating point number
Denotes a string
YAML is a very versatile data serialization standard that can be used to represent many different data types. In this shot, we learned to represent some of the most common data types in YAML.
- To learn more about the syntax, data types, and various key concepts related to the YAML language, check Educative's Introduction to YAML course.
View all Courses