Reputation: 175
I am trying to extract last id from a json array. Below mentioned is json array
[
{
"userInfo": {
"email": "jmeter1 @gmail.com",
"userName": " jmeter1"
},
"id": "2e13f399-5b51-13f0-05b2-623c726eaka1"
},
{
"userInfo": {
"email": " [email protected] ",
"userName": " jmeter2"
},
"id": "3e13f399-5b51-13f0-05b2-623c726eaga2"
},
{
"userInfo": {
"email": " jmeter3 @gmail.com ",
"userName": " jmeter3"
},
"id": "4e13f399-5b51-13f0-05b2-623c726eaha3"
},
{
"userInfo": {
"email": " jmeter4 @gmail.com ",
"userName": " jmeter4"
},
"id": "5e13f399-5b51-13f0-05b2-623c726eafa0"
}
]
` From above json i would like to extract value ie. id: "5e13f399-5b51-13f0-05b2-623c726eafa0".
Upvotes: 1
Views: 2611
Reputation: 825
Use the JSON Extractor and the JSON Path Expression $[-1].id
JMeter uses Jayway's jsonpath and as per the documentation there, [-1]
on an array will give you the last element. Test it here. Select Jayway implementation on the right.
Upvotes: 6
Reputation: 175
Extract id_matchNr(totalNumber of id by using Regular Expression Extractor)
use this ${__V(id_${id_matchNr})} expression to get the last id
Upvotes: 2
Reputation: 51
Use the following JSONPath Extractor configuration:
Refer extracted value as ${getid} where required.
Upvotes: 0