extract the a field value with same name from JSON using JMeter - jmeter

In the JSON response I have multiple fields with same name inside different tags . But I need to fetch the from that tag where matches the number I want. Say in the below examplele I want to fetch the value "(786)402-9010" when customerPpid=467133011
[{"oopId":"110034477","timestamp":"3698652681958","targetType":"TMTroubleCall","billAccount":"3655732026","customerFormattedPhoneNumber":"(786)505-2911","customerIsRequestingCallBack":"false","customerPpid":"609188407","acceptTime":"03/16/2018 11:31:00","originator":"DPH0GNL","priorityForDisplay":"3","remarks":"test","ddbKey":"8614147890T","displayType":"SNCU","parentFplId":"268224478","parentActualDeviceType":"TXU","parentDdbKey":"8614147890T","parentTroubleCoordinateX":"863634","parentTroubleCoordinateY":"459622","parentPreviousProtectiveDeviceStack":"268221704,23282601,23281142","toldItr":"03/16/2018 14:30:00","toldMode":"N","ticketCallComplaints":[{"componentId":"1685289","description":"No Current"}],"customerLanguageMenuOption":"1"},
{"oopId":"114249429","timestamp":"3698652636567","targetType":"TMTroubleCall","billAccount":"6182150000","customerFormattedPhoneNumber":"(786)402-9010","customerIsRequestingCallBack":"false","customerPpid":"467133011","acceptTime":"03/16/2018 11:31:00","attachTime":"03/16/2018 11:31:00","originator":"DPH0GNL","priorityForDisplay":"3","remarks":"testing","ddbKey":"8614154820T","displayType":"SNCU","parentFplId":"268224477","parentActualDeviceType":"TXU","parentDdbKey":"8614154820T","parentTroubleCoordinateX":"864084","parentTroubleCoordinateY":"459307","parentPreviousProtectiveDeviceStack":"268221704,23282601,23281142","toldItr":"03/16/2018 14:30:00","toldMode":"N","ticketCallComplaints":[{"componentId":"1685289","description":"No Current"},{"componentId":"4063885","description":"Customer checked breaker"}],"customerLanguageMenuOption":"1"},
how should i do it?

Add JSON Extractor as a child of the request which returns the above JSON
Configure it as follows:
Names of created variables: anything meaningful, i.e. phone
JSON Path Expressions:
$..[?(#.customerPpid == '467133011')].customerFormattedPhoneNumber
That's it, now you should be able to access the extracted value as ${phone} where required.
Demo:
References:
JSON Path Operators
JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

Use the following Json path expression
$..[?(#.customerPpid=="467133011")].customerFormattedPhoneNumber
Add a JSON extractor to the request as shown in the screenshot below
Please follow this Link for more info on extracting variables
Jmeter Json Extractor

Related

How to pass the dynamic value in Body data in the Post Request using jmeter

I recorded the .JMX script in Jmeter and one of the request is as below
POST http://www.hello.com/auth/nqa/md/login
Body data:
{"domainId":"nqa","code":"12345skdkdk"}
I would like to send the "code" field dynamically and for that I added the regular expressing extractor as below enter image description here
When i re run the script , the code value is not replaced with the dynamic value.
Not sure what part i am missing in the regular expression extractor or in the Body data field
First of all, you cannot extract the value from the request body using the Regular Expression Extractor, normally you should extract the dynamic values from the previous response so inspect the whole flow using View Results Tree listener and look for your "code" value there
Your regular expression extractor in its current configuration will return random value in the parentheses so it could be domainId, nqa, code or 12345skdkdk. Going forward if you need to get some dynamic data from JSON go for JSON Extractor or JSON JMESPath Extractor
List item
you should do three-step of below
go to the random variable according below picture
Define random variable name . in this case we set variable name to code1 and set min & max value to this
Use ${code1} variable to your data section

How I can get a random value string in href by JSON Path Extractor with JMeter?

I have JSON responce
{
"sessionName":"eL7tYgxhYh",
"imageSrc":"/Common/CaptchaImage/**eL7tYgxhYh**?t=636573960197174426"
}
How I can get a random value string "eL7tYgxhYh" in href by JSON Path Extractor with JMeter?
You cannot achieve this using JSON Extractor as it can only deal with JSON Objects, i.e. you can easily get full value of the imageSrc attribute, but not more.
I would recommend switching to Boundary Extractor instead, the relevant configuration would be something like:
Name of created variable: anything meaningful, i.e. href
Left Boundary: CaptchaImage/
Right Boundary: ?
That's it, the "interesting" value should be now extracted and you should be able to refer it as ${href} where required
Demo:
More information: The Boundary Extractor vs. the Regular Expression Extractor in JMeter
JSON format is in key-value pair so you just need to mention the key for which you need to extract the value. As in your case, you can use following JSON path expression for fetching the text mentioned by you:
$.sessionName
You can also use regular expression extractor which is another most important element of JMeter to extract the dynamic variables. Please refer to below blog of RedLine13 for more information on Regular Expressions:
https://www.redline13.com/blog/2016/01/jmeter-extract-and-re-use-as-variable/
Let me know if you have any further question
Above figure shows how to access access_token response of json and store it in access_token variable. In your case need to replace below.
JSONPath Expression use
$..sessionName
Destination variable Name
SessionName
more information for accessing json path
To Get "636573960197174426"
To get required string from result string you can use BeanShell Assertion to split the string.
And Use link to fetch the vaiable properties and jmeter elements
To Fetch jmeter Elements

JMeter - JSON Extractor post-processor

I've been trying to figure out how to configure a simple JSON Path extractor (provided on jmeter-plugins) and where to put it (inside an Http sample, outside...)
As you can see, ${expiredaccesstokenerror} is empty.
In order to fill this variable, I'm trying to extract a vallue from body response:
As you can see I'm trying to extract from json body content like:
{
"error_description":"Access token expired",
"suberror":"expired_accesstoken",
"error":"invalid_grant"
}
So, I've set JSON extractor for extracting $.suberror, however, it's always empty.
${expiredaccesstokenerror} in sampler is trying to get variable before request or response. In post processor you set the variable expiredaccesstokenerror but it's too late for displaying.

How to Re-use data generated by one Response to other request?

In my application while executing the first request one unique key is generated which key is required for Next all the request. let me how to automate such scenario in Jmeter.
The process should look as follows:
Add Post Processor to the first request
Configure it to extract the required value and store it into a JMeter Variable
Use JMeter Variable from step 2 in your next request.
Depending on response data type you have the following choices:
Regular Expression Extractor - for text
CSS/JQuery Extractor - for HTML
XPath Extractor - for XML and XHTML
JSON Path Extractor - for JSON
It is also possible to extract data from files i.e. if response is in PDF format, but it's a little bit tricky
Example configuration to store the whole response:
Reference Name: any suitable variable name, i.e. response
Regular Expression: (?s)(^.*)
Template: $1$
You can refer the extracted value as ${response} where required. You can also amend the regular expression to extract response part instead of the whole response. JMeter uses Perl5-compatible regular expressions, see Regular Expressions User Manual Chapter for details
You can use regular expression extractor to extract the key from the response of your first request and use the extracted key for subsequent requests. To achieve this:
Right click on the first request and add post processor: Regular Expression Extractor.
Create your regular expression and provide values in other required fields. Please refer to JMeter component reference http://jmeter.apache.org/usermanual/component_reference.html#Regular_Expression_Extractor
Extracted value will be saved in the variable given as reference name
Use this variable in subsequent requests
Here is an example test plan with results.

Regular expression in Jmeter for a json reponse

How do i write the regular expression for the json response.
My json response is "publisher":"/api/web/publishers/194".
From this response i want to get only the numeric value i.e 194. Some one pls help in getting it?
If "194" is the only integer in your response than your regex can be limited to just '(\d+)`
If you response contains more digits, you'll need to be more specific, like
"publisher":"/api/web/publishers/(\d+)"
So something like:
Reference Name: publisher
Regular Expression: "publisher":"/api/web/publishers/(\d+)"
Template: $1$
Will extract "194" and store it in "publisher" JMeter Variable. You'll be able to refer to it as ${publisher} later in Thread Group.
Going forward if you'll need to extract something from more complex JSON structures I'd recommend consider using JSON Path Extractor available via JMeter Plugins - the extractor lives in "Extras with Libs Set" package.
See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") for more information and XPath to JSON mapping.

Resources