Back to: YAML
Strings are used to represent text values. Strings can be written with or without quotes, and both single and double quotes are accepted. Here is an example of a YAML string:
name: John
In this example, “name” is the key and “John” is the string value associated with it.
Strings can also contain special characters and escape sequences. Here is an example of a string with a newline character:
greeting: "Hello\nWorld"
In this example, the “\n” sequence represents a newline character, which will be displayed as a line break when the string is rendered.
Strings can also be written with double quotes, which allows for more escape sequences. Here is an example:
greeting: "Hello, \"World\"!"
In this example, the string value contains double quotes around the word “World”. To include the double quotes in the string, they are escaped using a backslash “”.
Multi-line strings are also supported in YAML using the “|” character. Here is an example:
message: |
This is a multi-line
string in YAML.
Follow us on social media
Follow Author