Original file controls: - id: AC-1 levels: - high - moderate - low - id: AC-2 When i add a new field to mapping, it looks like this, rules is the new added field.It adds a new extra new line. controls: - id: AC-1 levels: - high - moderate - low rules: [] - id: AC-2 But i want this, is this possible. controls: - id: AC-1 levels: - high - moderate - low rules: [] - id: AC-2 I saw there is a similar question Modifying YAML using ruamel.yaml adds extra new lines, but i believe this is very old. Continue reading...