0
votes

I am making an HTTP request using Apache JMeter.

The response has the following format:

HTTP/1.1 100 Continue

HTTP/1.1 200 OK x-powered-by: Express access-control-allow-origin: * access-control-allow-methods: HEAD, POST, PUT, GET, OPTIONS, DELETE access-control-allow-headers: origin, content-type, X-Auth-Token, Tenant-ID, Authorization content-type: application/json; charset=utf-8 content-length: 24 etag: W/"18-8MkH0L5c1ZW7PPuEY1rZ3jKFme0" date: Thu, 08 Apr 2021 12:28:37 GMT x-envoy-upstream-service-time: 90 server: envoy

{"id":"548b23a3.4f6a4c"}

I need a way to extract the JSON id value to a variable to make another one request.

JSON extractor needs a pure JSON format as response but in my case i need to skip all these headers from the body response.

Any ideas how could i make it with the Apache JMeter?

2

2 Answers

0
votes

If you really have all this as a part of response body (however it looks like Headers to me) you should always be able to fall back to the Regular Expression Extractor which doesn't have any limitations.

Example regular expression:

"id"\s*:\s*"(.+?)"}

Demo:

enter image description here

Explanation:

  • \s - meta character for whitespace
  • * - any number of whitespaces
  • . - match any character
  • + - repetition
  • ? - don't be greedy, stop at first match

More information:

0
votes

Another clean way is to use is JSON Extractor (Post Processor). This is pretty helpful when you will have complex json (multiple nested objects) returned.

Extracting JSON values

More details here: https://octoperf.com/blog/2017/03/09/how-to-extract-data-from-json-response-using-jmeter/#jmeter-jsonpath-plugin