English 中文(简体)
YAML – Block Scalar Header
  • 时间:2024-12-27

YAML - Block Scalar Header


Previous Page Next Page  

In this chapter, we will focus on various scalar types which are used for representing the content. In YAML, comments may either precede or follow scalar content. It is important to note that comments should not be included within scalar content.

Note that all flow scalar styles can include multiple pnes, except with usage in multiple keys.

The representation of scalars is given below −

%YAML 1.1
---
!!map {
   ? !!str "simple key"
   : !!map {
      ? !!str "also simple"
      : !!str "value",
      ? !!str "not a simple key"
      : !!str "any value"
   }
}

The generated output of block scalar headers is shown below −

{
   "simple key": {
      "not a simple key": "any value", 
      "also simple": "value"
   }
}

Document Marker Scalar Content

All characters in this example are considered as content, including the inner space characters.

%YAML 1.1
---
!!map {
   ? !!str "---"
   : !!str "foo",
   ? !!str "...",
   : !!str "bar"
}

%YAML 1.1
---
!!seq [
   !!str "---",
   !!str "...",
   !!map {
      ? !!str "---"
      : !!str "..."
   }
]

The plain pne breaks are represented with the example given below −

%YAML 1.1
---
!!str "as space 
trimmed

specificL

none"

The corresponding JSON output for the same is mentioned below −

"as space trimmed
specificu2028
none"
Advertisements