2

I am a beginner with Jmeter tool. I use JMeter to hit a URL and obtained a response message in JSON format. I want to parse the response to extract every array element and use it to append to the tail of another URL. Can you please tell me how to do this?

example: { "reply": { "code": "111", "status": "SUCCESS", "customer": [ "222-a", "b-333", "44-4", "s-555", "666", "777", "88-8" ] } } 
1
  • example: { "reply": { "code": "111", "status": "SUCCESS", "customer": [ "222-a", "b-333", "44-4", "s-555", "666", "777", "88-8" ] } } Commented Jun 20, 2013 at 6:02

1 Answer 1

7

You can use a Regular Expression Extractor (as child of your URL sampler) to first extract the array of values:

Reference name: ary
Regular Expression: \[([^\]]+)\]
Template: $1$
Match No: 1

then use another Regular Expression Extractor to extract the values:

Apply To JMeter variable: ary

Reference name: vals
Regular Expression: "([^"]+)"
Template: $1$
Match No: -1

The match no -1 creates variables vals_1 .. vals_7, which you can then use in a ForEach Controller to assign to a JMeter variable:

Input variable prefix: vals
Output variable name: id
[v] Add '_' before number?

now you can use the JMeter variable ${id} in a nested URL sampler to pass the customer id in a URL.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very much for your response. Your last comment is what exactly I am trying to do "now you can use the JMeter variable ${id} in a nested URL sampler to pass the customer id in a URL." but in a different thread group. Can you please tell me how to use this variable in the following thread group. Thank you
Looping through all output of a RegExp extractor. Can you please tell me how to loop through the result of a Regex Post Processor that returns multiple values?
@Sashi, JMeter variables are local to the current thread, as far as I know you cannot pass them to other threads. However you could try to save them (in the foreach controller) to a file which is used in a CSV controller in the next thread group, see stackoverflow.com/questions/8352281/… (btw, I never tried this.)
@Sashi, the Foreach controller assigns the values to a variable (id in the text above) which you can expand in URL samplers that are child nodes of the foreach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.