Skip to content

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

Closed
@Giszmo

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

puzrin

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

reopened this on Jul 23, 2020
Giszmo

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
})}
...
added a commit that references this issue on Dec 10, 2020
rlidwka

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.

14 remaining items

Loading
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

        Participants

        @Giszmo@puzrin@rlidwka

        Issue actions

          writer: provide option where null values are just empty. · Issue #570 · nodeca/js-yaml