Reputation: 67
I am working with YAML files and I am stuck in using the "|" for literal quotes.
I am using PyYAML.
Major issue here is that it works for the first level "Dictionary" Key in the below code but for the second level "notes" key it did not work.
I have tried using ">" "|+" "|-" but nothing worked.
Description: |
This is a sample text showing that it works fine here.
Signatures:
- {
returnValue: 'placeholder',
notes: |
Its not working here
}
- {
returnValue: 'another placeholder',
notes: '
This is working here
'
}
I checked the syntax on http://yaml-online-parser.appspot.com/ , https://nodeca.github.io/js-yaml/ and others as well, I got the error that
ERROR: while scanning for the next token found character '|' that cannot start any token in "", line 8, column 24: notes: |
I went through the thread In YAML, how do I break a string over multiple lines? and few others, but nothing worked.
Upvotes: 1
Views: 124
Reputation: 76902
First, always make the minimal example that throws the error:
{ notes: |
Its not working here
}
If you look at the YAML specification and search for the string "literal style" your first hit is in the Table of Cotents, section 8.1.2 which is part of the description of Block styles
Your code specifies flow style for the mapping with its use of { }
, within that you cannot have block style literal scalars.
You should just make the whole YAML consistently block style (remove the {}
and the ,
between mapping elements):
Description: |
This is a sample text showing that it works fine here.
Signatures:
- returnValue: placeholder
notes: |
Its not working here
- returnValue: another placeholder
notes: '
This is working here
'
BTW, because default chomping on literal scalars is clipping, it doesn't change anything if you add extra empty lines at the end of such scalars.
(PyYAML only supports YAML 1.1, but wrt this the specification has not changed).
Upvotes: 2