scalars refer to simple values such as strings, numbers, and boolean values. Scalars are used to represent basic data types in YAML documents. Here is a code example of YAML scalars:
name: John age: 30 isMarried: true favoriteFoods: - pizza - sushi
In this example, “name” is a scalar string value, “age” is a scalar integer value, “isMarried” is a scalar boolean value, and “favoriteFoods” is a scalar list value. The list contains two scalar string values: “pizza” and “sushi”.
Scalars can be written in several ways in YAML. Strings can be written with or without quotes, and both single and double quotes are accepted. Here is an example:
All three of these examples are valid scalar string values in YAML. The first two examples use quotes, while the third example does not.
Integers and floats are also supported in YAML. Here is an example of a scalar integer value:
And here is an example of a scalar float value:
Boolean values are represented using the words “true” and “false”. Here is an example:
Lists are represented using hyphens “-” followed by a space. Here is an example of a scalar list value:
favoriteFoods: - pizza - sushi
Follow us on social media