Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Giszmo opened this issue Jul 22, 2020 · 3 comments
Closed

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

Giszmo opened this issue Jul 22, 2020 · 3 comments

Comments

@Giszmo
Copy link

Giszmo commented Jul 22, 2020

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

$ dump(load("something: "))
something: null
@puzrin
Copy link
Member

puzrin commented Jul 23, 2020

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

@puzrin puzrin closed this as completed Jul 23, 2020
@puzrin puzrin reopened this Jul 23, 2020
@Giszmo
Copy link
Author

Giszmo commented Jul 23, 2020

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
})}
...

@rlidwka
Copy link
Member

rlidwka commented Dec 10, 2020

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.

@rlidwka rlidwka closed this as completed Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants