I have the following JSON string:
{
"myKey": "myValue"
}
I want to check whether this string is not empty. I can do this:
$.myKey
to get the value of myKey. I've tried changing it to
$.[?(@.myKey.length()>0)]
(as per this topic Expression to filter out elements with empty arrays using `jsonPath`) or even this:
$.myKey.length()>0
but I get error that it is not a valid JSONPath expression.
I add "JsonPath Match" to the test step in my project. When I set it to
$.myKey
and press "Select from current", it works. For
$.[?(@.myKey != '')]
when I press "Select from current", I get
"Invalid JsonPath expression"
I use SoapUI 5.4.0 but I don't know how to check its JsonPath implementation. I want to get false if string is empty.
How can I check whether myValue is empty or not? Thanks!
The following jsonpath filter: $.[?(@.myKey != '')] will return the document if the attribute myKey is not an empty string.
You can verify this using the Jayway JsonPath evaluator.
If this ...
How can I check whether myValue is empty or not?
... means something like: "I only want to return the document if myKey is populated" then the above jsonpath filter should suffice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With