Sashi
Sashi

Reputation: 151

Parse an array from the response message using JMeter

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" ] } } 

Upvotes: 2

Views: 8530

Answers (1)

rsp
rsp

Reputation: 23373

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.

Upvotes: 7

Related Questions