Sobhana
Sobhana

Reputation: 175

How to get last id from json response in jmeter?

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

Answers (3)

riyasvaliya
riyasvaliya

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

Sobhana
Sobhana

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

Suresh Kharod
Suresh Kharod

Reputation: 51

Use the following JSONPath Extractor configuration:

  • Destination Variable Name: any name of your choice, i.e. getid
  • JSONPath Expression: $..id[0]

Refer extracted value as ${getid} where required.

Upvotes: 0

Related Questions