technogecko
technogecko

Reputation: 30

JMeter Json Extractor for Multiple Http Requests

I have setup a ForEach Controller to execute multiple HTTP requests but I would like to then extract JSON values from the response bodies from each of the HTTP requests.

When I try to add a JSON Extractor PostProcessor to the HTTP Request, I am only able to get a json value from the last HTTP Request. Is it possible to get values from all of the HTTP requests?

Upvotes: 0

Views: 1306

Answers (2)

Dmitri T
Dmitri T

Reputation: 168002

You're getting the values from each HTTP Request, you just overwrite the previous value when the next iteration of the ForEach Controller starts, you can double check yourself by adding Debug Sampler after the HTTP Request sampler under the ForEach Controller

Just add ${__jm__ForEach Controller__idx} pre-defined variable as a prefix or postfix for the name of the created variable in JSON Extractor so on each iteration it will create a separate JMeter Variable holding the current value extracted from the response.

Example configuration:

enter image description here

Demo:

enter image description here

Upvotes: 1

Gaganpreet Sran
Gaganpreet Sran

Reputation: 11

JSON extractor is ok but something that you can try and is more flexible i add beanshell post processor and choose your language, then you can extract the JSON from HTTP requests. You can choose java as language and use following code to extract the JSON as string

String jsonString = prev.getResponseDataAsString();

Upvotes: -1

Related Questions