jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
4.91k stars 1.77k forks source link

null keys #1269

Open oleorhagen opened 4 months ago

oleorhagen commented 4 months ago

Hello :wave: :smile_cat:

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 commented 4 months ago

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 commented 4 months ago

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 :smile:

InitialZJ commented 4 months ago

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