-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
"null" key parses as the empty string #554
Comments
The issue that you're encountering is that the JS Object only supports string keys, and the If you're working with data that may include non-string keys, you could try one of the following approaches:
|
Thanks for the thoughtful response. I acknowledge that the YAML spec nods to non-string native types being supported on parse. I’m curious from your perspective, as the library author, why treating keys as strings isn’t the default behavior, given that traditionally POJOs are our mapping type in JS. In other words, I would’ve guessed that non-string scalar keys would be behind a flag, and string keys would be the default. Maybe as I research the fail safe flag I’ll learn more :-) |
Because this is a YAML library, and YAML explicitly allows and supports non-string keys. |
sure, but just because yaml supports it doesn’t mean it must be processed. Some languages dont even have null. I presume they get parsed as “null”. Is it incorrect to parse as strings? A casual scan of the spec suggests that it is not a problem. Thus, why wouldn’t we parse using JS friendly behavior first? What use cases in JS would someone want non strings parsed into a JS object key? |
The default schema used by this library is the YAML 1.2 core schema, which defines quite exactly how plain scalars are to be parsed, independently of where in the document structure they show up.
Because this library is seeking to provide an accurate representation of a YAML document, which may contain mappings that have non-string keys. Please also note that you're effectively asking for a breaking change, which I would prefer not to do unless there's a really strong case for such a change. |
Describe the bug
null as a key is parsed as the empty string:
To Reproduce
Expected behaviour
Versions (please complete the following information):
yaml
: "2.4.3"Additional context
The text was updated successfully, but these errors were encountered: