Skip to content

writer: provide option where null values are just empty. #570

Closed

Description

@Giszmo

If empty gets read as null, it should at least optionally be possible to also write null as empty.

$ dump(load("something: "))
something: null

Activity

  1. puzrin commented on Jul 23, 2020

    @puzrin
    Member

    https://github.com/nodeca/js-yaml#safedump-object---options-

    There are styles to select dumping formats when possible. IMO you can create schema with customize null type, if existing not enough

  2. reopened this on Jul 23, 2020
  3. Giszmo commented on Jul 23, 2020

    @Giszmo
    Author

    I think I could help myself but it looks hacky:

    const schema = yaml.DEFAULT_SAFE_SCHEMA
    schema.compiledTypeMap.scalar['tag:yaml.org,2002:null'].represent.lowercase = function() { return '' }
    file.write(`---
    ${yaml.safeDump(header, {
      schema: schema
    })}
    ...
    
  4. added a commit that references this issue on Dec 10, 2020
  5. rlidwka commented on Dec 10, 2020

    @rlidwka
    Member

    Fixed in 421ed22 (located in dev branch at the moment).

    Normally, I'd advise to override null schema. But some other parsers (namely, psych and ruamel.yaml) serialize null this way, so it makes sense to at least provide an option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions