Reputation: 379
I'm facing issue with a jsonpath to extract element from json.
Here is an example of the json:
[
{
"idA":"104",
"idB":"2941",
"idC":"13316",
"idE":"13361",
"idF":"12758",
"idG":"12865",
"idH":[
]
},
{
"idA":"104",
"idB":"2941",
"idC":"13317",
"idE":"13362",
"idF":"12759",
"idG":"12866",
"idH":[
"10391"
]
},
{
"idA":"104",
"idB":"2941",
"idC":"13318",
"idE":"13363",
"idF":"12760",
"idG":"12867",
"idH":[
]
}
]
Here is the jsonpath:
$[?(@.idH[0]!=null)]
The goal is to get the element where idH is not null. It works on few json online evaluators from whom I get what I expected:
[
{
"idA": "104",
"idB": "2941",
"idC": "13317",
"idE": "13362",
"idF": "12759",
"idG": "12866",
"idH": [
"10391"
]
}
]
But it fails on others few online evaluators too, returning for example "An error occurred with JSONPath."
Unfortunately, it doesn't work with Json extractor in Jmeter, because I get the first element of the json, like if the jsonpath would have been $[0]
Any Idea what is the problem here? Thanks in advance for any help, clue or idea.
For information in case, I use Apache JMeter (5.3)
Upvotes: 0
Views: 1962
Reputation: 168072
How about using JSON Extractor which allows executing arbitrary JsonPath queries
You should be able to get the object you're looking for as simple as:
$..[?(@.idH[0])]
Demo:
More information: API Testing With JMeter and the JSON Extractor
Upvotes: 2