|
を利用して、複数行の文字列が書ける。
---
key: |
Line 1
Line 2
Line 3
array:
- |
This is the first line
This is the third line
And the last line
出力したJSON:
{
"key": "Line 1\nLine 2\nLine 3\n",
"array": [
"This is the first line\nThis is the third line\nAnd the last line\n"
]
}
最後の改行を消したい場合、|
の後ろに-
を追加することで実現できる:
---
array:
- |-
This is the first line
This is the third line
And the last line
出力したJSON:
{
"array": [
"This is the first line\nThis is the third line\nAnd the last line"
]
}
注意する必要なのは、インデントが一行目が基準なので、以降の行は一行目より少ないインデントはNGだ。
---
array:
- |-
This is the first line
This is the third line
And the last line
出力したJSON:
{
"array": [
"This is the first line\n This is the third line\n And the last line\n"
]
}
下記はNG(2行目のインデントが1行目より少ない)
---
array:
- |-
This is the first line
This is the third line
And the last line