Reputation: 9
I need to extract specific value from JSON response (or text) with a condition (another JSON value):
I have this response:
{
"availabilityPercentage": "0.7713",
"availability": [
{
"date": "2021-03-05",
"estimators": [
{
"skills": [
"Non-Driveable"
],
"estimatorId": "99999999-0000-0000-9999-000000000002",
"timeSlots": [
{
"timeFrom": "08:00",
"isAvailable": false,
"timeTo": "08:30",
"slot": "MjAyMS0wMy0wNSUwODowMDowMCUwODozMDowMA"
},
{
"timeFrom": "08:30",
"isAvailable": true,
"timeTo": "09:00",
"slot": "MjAyMS0wMy0wNSUwODozMDowMCUwOTowMDowMA"
},
{
"timeFrom": "09:00",
"isAvailable": false,
"timeTo": "09:30",
"slot": "MjAyMS0wMy0wNSUwOTowMDowMCUwOTozMDowMA"
}
}
]
}
]
}
] }
And I want to extract only "slot" value when "isAvailable" is true.
How can I do it with JMeter?
Thanks in advance.
Regards
Upvotes: 0
Views: 643
Reputation: 168072
You can use JSON JMESPath Extractor which allows executing arbitrary JMESPath queries which is probably the most powerful way of getting data from JSON responses
Example JMESPath query:
availability[*].estimators[*].timeSlots[?isAvailable==`true`].slot | [0] | [0]
Demo:
More information: The JMeter JSON JMESPath Extractor and Assertion: A Guide
Upvotes: 1
Reputation: 2074
Please try the below, use a JSON extractor and put this condition.
$..[?(@.isAvailable == true)].slot
Also please check your JSON is not formatted correctly
Upvotes: 0