I use the YAML component of Symfony to parse the YAML in this question.
I have the following YAML:
The answer to both questions is yes. Adding a additional key value pair to the top-level, or any other of the mappings should not affect the final newline of the folded scalar.
>, folded block style, you always get one newline at the end of the file, because the default is clipping:
Clipping is the default behavior used if no explicit chomping indicator is specified. In this case, the final line break character is preserved in the scalar’s content. However, any trailing empty lines are excluded from the scalar’s content.
If you don't want that, use an explicit chomping operator, in this case, to strip, use
>- instead of just
>. (Assuming of course that your parser interprets that correctly).
In Python, using ruamel.yaml (of which I am the author) this works correctly:
import ruamel.yaml yaml_str = """\ db_driver: orm service: user_provider: user_provider options: supported_scopes: >- user_basic_information internal """ data = ruamel.yaml.safe_load(yaml_str) print(repr(data['service']['options']['supported_scopes']))