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

Non-existent keys should not return null #188

Open
An-dz opened this issue Aug 12, 2020 · 0 comments
Open

Non-existent keys should not return null #188

An-dz opened this issue Aug 12, 2020 · 0 comments

Comments

@An-dz
Copy link

An-dz commented Aug 12, 2020

One thing that caught my attention right after reading the documentation is that trying to access a key that does not exist returns null. And thus this code works without panicking:

fn main() {
    let null_test = json::object! {
        bar: null,
    };

    assert!(null_test["foo"] == null_test["bar"]);
}

There's a distinction between something that is undefined and a key with a null value but this crate does not have it.

This causes implications like introducing a bug where the wrong key name is used but the code won't complain because it will constantly accept that the value was null, even though the function may fail and thus not report. As an example think that if bar exists I know that part worked and returned nothing, while the service foo failed completely and thus was not appended.

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

1 participant