Sajan Jacob K
Sajan Jacob K

Reputation: 524

Can we use variable in JSONPath expressions in JSON Extracter of JMeter

we use jSON Path expression in JSON Extracter in like: $.store.book[0].title

can we use a JMeter variable instead? like: ${myexpression}

Upvotes: 0

Views: 901

Answers (1)

Adnan
Adnan

Reputation: 2547

Yes you can do that. I am providing a sample test which uses CSV dataset config to pick up the JSON Path Expression. Also used variable in the JSON Extractor field. JSON Response :

{
  "firstName": "John",
  "lastName" : "doe",
  "age"      : 26,
  "address"  : {
    "streetAddress": "naist street",
    "city"         : "Nara",
    "postalCode"   : "630-0192"
  },
  "phoneNumbers": [
    {
      "type"  : "iPhone",
      "number": "0123-4567-8888"
    },
    {
      "type"  : "home",
      "number": "0123-4567-8910"
    }
  ]
}

Path Expression: $.phoneNumbers[:1].type which is in a CSV file.

CSV Data sest config:

enter image description here

JSON Extractor Setting:

enter image description here

Extracted value fed to the next request:

enter image description here

Check in View Results tree listener:

enter image description here

Upvotes: 1

Related Questions