Block Scalars
For multiline strings, YAML provides block scalar styles. Block literals (|) and block folded style (>) are two types.
A. Block Literal Style (|): Block literal style preserves newlines and leading whitespaces. It allows for clean representation of multiline strings.
Example:
message: |
This is a multiline
string with special characters: \\, \", \', \n, \t.
In this example: The | denotes the block literal style. The content following | is treated as a multiline string.
Output:
This is a multiline
string with special characters: \\, \", \',
B. Block Folded Style (>): Block folded style is similar to block literal style but it folds newlines into spaces unless a newline is followed by an empty or indented line.
Example:
message: >
This is a multiline
string with special characters: \\, \", \', \n, \t.
In this example: The > denotes the block folded style. The content following > is treated as a multiline string.
Output:
This is a multiline string with special characters: \\, \", \',
How To Escape The Special Character In YAML With Examples ?
YAML (YAML Ain’t Markup Language) is a popular human-readable data serialization format often used for configuration files and data exchange. In YAML, special characters must be properly escaped to ensure they are interpreted correctly. In this article, we will learn, How to escape the special character in YAML.
Contact Us