#441·js-yaml

Feature request: vertical whitespace option

Author: JamesMessingerCreated Sep 1, 2018Updated Dec 10, 2023

When serializing an array of objects using the dump() or safeDump() methods, js-yaml currently produces output like this:

yaml
customers:
  - name: John Doe
    age: 40
    something: some value
    anotherThing: another value
    etc: more stuff here
  - name: Jane Doe
    age: 35
    something: some value
    anotherThing: another value
    etc: more stuff here
  - name: Bob Smith
    age: 42
    something: some value
    anotherThing: another value
    etc: more stuff here
nextProperty:
  someKey: some value
  someOtherKey: some other value

The problem is that it's difficult to read because there's no visual separation between each object in the array. I'd love a new option to the dump() and safeDump() methods that puts vertical whitespace (i.e. a blank line) after objects in arrays. When this option is set, the output would look like this:

yaml
customers:
  - name: John Doe
    age: 40
    something: some value
    anotherThing: another value
    etc: more stuff here

  - name: Jane Doe
    age: 35
    something: some value
    anotherThing: another value
    etc: more stuff here

  - name: Bob Smith
    age: 42
    something: some value
    anotherThing: another value
    etc: more stuff here

nextProperty:
  someKey: some value
  someOtherKey: some other value

Notice that there's even a blank line after the last object in the array. This visually separates it from the next property on the parent object.