Reputation: 1
I want to extract the key value from the JSON response received for a login web service and pass that key value to all other subsequent services.
Note: This key value is dynamic.
The JSON response looks like this:
{
"key":"jwtjWgwnqIVapQeDh47rkFaKV6E",
"username":"Tester",
"password":"xyz",
"servername":"123.45.6.789",
"mailpath":"mail/tmail5.nsf",
"pin":"xxxx",
"defaultAttachments":"OFF",
"sendMailsFor":"W-1",
"serverTime":"10/09/2012 20:02:57"
}
Please help me in writing the reqular expression to extract the same and to pass that key value to all other next web services.
Please let me know what should I write in the fields "Reference Name:", "Regular Expression:", "Template:", "Match No.:" and how to declare the "Reference Name" in the next web services.
Thanks!
Upvotes: 0
Views: 8866
Reputation: 12873
If key
appearance is unique in response you may simply use Regular Expression Extractor added to the HTTP Request which returns json response, with regex like following:
HTTP Request
Regular Expression Extractor
Reference Name: authKey
Regular Expression: "key":"(.+?)"
Template: $1$
Match No.: 1
and refer extracted value as ${authKey}
in all the further requests/samplers across your test.
As well you can look into this for the same situation.
And please don't be lazy in future to look first a bit around: it can appear that answer to your question already exists here.
Upvotes: 1