Reputation: 486
Here is my response code I want to retrieve the last id always using JSON extractor and further how can I pass this id to another HTTP Request in POST parameter
{
"response": [
{
"dm": "CL 6",
"id": 3,
"yN": "t1-cl -6"
},
{
"dm": "CL 2",
"id": 4,
"yN": "t1- cl -2"
}
],
"timestamp": "2020-04-02T22:40:42.416",
"status": "OK"
}
What I have tried in JSON extractor
but it does not return anything. I even tried $..id[-1]
further, I need to pass this id to another HTTP Request in POST parameter
Upvotes: 0
Views: 230
Reputation: 168157
Your configuration should generate the following JMeter Variables:
extract_id_1=3
extract_id_2=4
extract_id_matchNr=2
So the "last" ID can be obtained using __V() function as follows:
${__V(extract_id_${extract_id_matchNr})}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables
Upvotes: 0
Reputation: 2978
Use this as JSON Path Expressions: $.response[-1:].id
This will return the last id
from the response
array objects.
Upvotes: 1