Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to properly check a JSONPath for existance?

by kroach (Pilgrim)
on Apr 02, 2018 at 16:24 UTC ( [id://1212179]=note: print w/replies, xml ) Need Help??


in reply to How to properly check a JSONPath for existance?

The documentation says the values() method returns the number of matches but it doesn't seem to be the case since in your example it returns undef for both a non-existent element and a null one. Since you check for defined(), they both return false.

What you can do is call values() in list context and check for the number of matches. The non-existent entry should have none and null should have a single undef entry.

my @values = $json_path[$i]->values($json); if (@values > 0) { print("exists\n"); } else { print("does not exist\n") }

Replies are listed 'Best First'.
Re^2: How to properly check a JSONPath for existance?
by Bloehdian (Beadle) on Apr 02, 2018 at 17:26 UTC

    Works! Thanks a lot!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1212179]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 11:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found