1
votes

I'm using the regular expression extractor in JMeter to extract data from a parameter. However, the data is not being extracted.

Response:

{
    "access_token": "8d06ba17-2e51-31d2-aa55-25e4a3ecd33b",
    "expires_in": 7200
}

Extractor:

Name reference: token
Regular expression: "access_token": "(.+?)"
Match: $1$

Request parameter use

v1/api/users?client=${token}
2

2 Answers

1
votes
  1. Your access_token is a GUID-like structure so you can use the following regular expression instead:

    ([A-Fa-f0-9]{8}[\-][A-Fa-f0-9]{4}[\-][A-Fa-f0-9]{4}[\-][A-Fa-f0-9]{4}[\-]([A-Fa-f0-9]){12})
    

    enter image description here

  2. Alternatively you can try to secure yourself by adding optional whitespace meta character like:

    "access_token"\s?:\s?"(.+?)"
    

    enter image description here

More information:


  1. And finally your response is in JSON format so it makes more sense to use JSON Extractor, the relevant JsonPath query would be as simple as:

    $.access_token
    

    enter image description here

2
votes

Use instead JSON Extractor with JSON Path Expressions as $.access_token

JSON PostProcessor enables you extract data from JSON responses using JSON-PATH syntax. This post processor is very similar to Regular expression extractor. It must be placed as a child of HTTP Sampler or any other sampler that has responses. It will allow you to extract in a very easy way text content