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

null keys #1269

Open
oleorhagen opened this issue Feb 2, 2024 · 4 comments
Open

null keys #1269

oleorhagen opened this issue Feb 2, 2024 · 4 comments

Comments

@oleorhagen
Copy link

Hello 👋 😸

I am currently having a problem with null keys in Yaml. AFACT this is a valid Yaml key and value:

null: null

However, the following:

auto y = yaml::Load("null: null");
y["null"] <- non-existent key 'null'

I understand that this is most likely a pilot error, but have not been able to see my mistake. So I just wanted to double check. Is this me, or is this the libraries fault?

@jbeder
Copy link
Owner

jbeder commented Feb 2, 2024

Good question. Null does get mapped to a null object by the core schema, but I would have thought you could access it like a string key if you wanted.

Not sure why it's doing that. Happy to accept a PR.

@oleorhagen
Copy link
Author

Good question. Null does get mapped to a null object by the core schema, but I would have thought you could access it like a string key if you wanted.

Not sure why it's doing that. Happy to accept a PR.

Sweet - I'll see what I can do 😄

@InitialZJ
Copy link

I compared it with the PyYAML library in python. When the input is null: null, the output is {None: None}. At this time, you can use data[None] to obtain and modify the value, but in this library, null cannot be used as key.

image

@SGSSGene
Copy link
Contributor

SGSSGene commented Aug 22, 2024

To make this work you need to use YAML::Null as a key.

    auto y = YAML::Load("null: null");
    y[YAML:Null]; // <- key YAML::Null exists

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

4 participants