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

Access nested object properties #45

Closed
bartbutenaers opened this issue Aug 24, 2021 · 1 comment
Closed

Access nested object properties #45

bartbutenaers opened this issue Aug 24, 2021 · 1 comment

Comments

@bartbutenaers
Copy link

Dear,

Thanks for sharing this very useful library!

I'm a bit confused about nested object properties.
I pass an object like this:

image

Which we try to validate using following expression:

msg.payload.open == true

From the readme page I understood this should be possible:

image

But I might have misinterpreted this??
And indeed while debugging, I see that this library checks whether the object has its own property "msg.payload.open" which is of course not the case:

image

Which means the nested property cannot be found :-(

However when I change the code to this:

    function prop(name, obj) {
        return name.split('.').reduce((obj, prop) => {
            return obj && obj[prop] ? obj[prop] : undefined;
        }, obj)
    }

    function safeGetter(obj) {
        return function get(name) {
            return name.split('.').reduce((obj, prop) => {
                return obj && obj[prop] ? obj[prop] : undefined;
            }, obj)
        }
    }

Then the nested property can be found without problems:
image

Thanks !!!
Bart

@cshaa
Copy link
Owner

cshaa commented Sep 17, 2021

Closing this in favor of #44. If there's anything to discuss, let's discuss it there :)

@cshaa cshaa closed this as completed Sep 17, 2021
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

2 participants