Overview of data types in YAML
In this lesson, you would learn about various data types in YAML and their usage.
Data types in YAML
YAML supports most of the data types of agile programming languages such as Perl, Python, PHP, Java, C#, Ruby, and JavaScript.
The following is the list of supported data types:
- Boolean
- Numbers
- Strings
- Dates
- Timestamp
- Arrays
- Maps
- Null
Variable (Scalars)
A name followed by a colon (:
) and a single space (
) defines a variable. Variables can also be referred to as scalars.
See the example below about how to represent variables in YAML.
Example
string: "Hello"
integer: 123
float: 12.345
boolean: No
Below is the graphical representation of the example above:
String variable
Strings can be written without quotes or enclosed within a pair of '
single or "
double quotation symbols.
Example
name: !!str "James"
message: !!str "This is a \n multiline text"
Below is the example to demonstrate the different ways of representing Strings in ‘YAML’.
Example
text: Hello
quoted:
- 'single quoted string'
- "double quoted strings"
Below is the graphical representation of the above example:
Note:
A |
character denotes a string with newlines, indentations and spaces preserved. This is also referred to as pipe notation in YAML. See its usage in the example below.
...