Search code examples
jsonjmeterbeanshell

Decode json in Jmeter and use one response's varible for another request


I have a question that I just not find the full answer. I am using Jmeter 3.2, and using json in request, the problem is that I get encode response (%20france and not France). I read in net how to decode the response and move it to a file or a variable, But I do not want to do it, I want to decode the response and then to parse it using the json extractor, and take for example the ID field and put it in the next request. can someone please advise with step by step solutions regards

to be more specific 1. send a json request in jmeter 2. decode the response in jmeter 3. Take the ID field from decode response 4. put ID from step 3 in a new json request


Solution

  • Here is the procedure:

    1. Add your sampler or request in your thread group. Configure all the fields as your requirements. (i.e Server IP, port, method, Body data etc)

    2. Add an HTTP Header Manager to send the Content-Type header with the value of application/json

    3. Add a JSON Path Extractor under your sampler/request to extract the response. (Put any variable name where your extracted ID will be saved, give the correct expression in JSON Path expression to parse it, use NOT_FOUND as the default value).

    Demo: enter image description here

    1. Now you can use that variable in your subsequent request.

    Demo: enter image description here