Skip to content

paths creates paths if they do not exist #13

Description

@tobyink

Migrated from rt.cpan.org #133925 (status was 'open')

Requestors:

From pcronin@cpan.org on 2020-12-20 12:14:37
:

Hi Kit,

Thanks very much for keeping this module going! I'm not sure if this is intended behavior or not, but it's not desirable for my use case, so I'll just mention it here. When using the paths method to get canonical paths for a JSONPath expression in an object, it creates those paths if they don't exist. The docs only mention that kind of behavior for the value and set methods, so I was surprised to see it for paths as well.

Here's a simple example:

$ perl -MJSON::Path -MDDP -e '$x={};@y=JSON::Path->new("$.a")->paths($x);p $x;p @y';
\ {
a undef
}
[
[0] undef
]

I'd have expected $x to remain an empty hashref because the JSONPath expression doesn't exist in it. I would also not expect an undef to be included in the found paths (I'd have expected an empty arrayref in this case.)

Am I thinking of this method in a way that wasn't intended?

If you think this is a bug, I can put together a PR to fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions