how to specify nested json path in jmespath and jmeter - jmeter

My jmeter test receives the following json response
{"result":"success","additional-info":"{"external-profile":{"email":"myemail#gmail.com","firstname":"fn","lastname":"ln","portfolio":{"tags-of-interest":[],"question-created-tags":[{"tag":"un2-new tag-empty","count":1},{"tag":"un2-new tag2-empty","count":1}],"question-answered-tags":[]}}}"}
I am trying to validate that a path exists. I am able to validate that the top level path exists but I can't validate that the nested path exsits.
Eg. validating "additional-info" works but "additional-info"."external-profile" doesn't. What am I doing wrong?
This works
This fails with error JMESPATH "additional-info"."external-profile" expected to exist

Just go for 2 JSON JMESPath Extractors:
Extract the content of additional-info attribute into a JMeter Variable from the response
Extract the attributes from the external-profile attribute:
You can see the extracted values using Debug Sampler and View Results Tree listener combination:

Related

Using JsonExtractor Value in Jmeter

I have like 3 JsonExtractors in a single thread. How do i use the value extracted from the first to the third ?
The first JsonExtractor extracts 'winSpoke' value from the response json and i am storing in as
Names of created variables: WinSpoke
The third JsonExtractor will extract 'payLevelDetails' value based on the previous WinSpoke value and i am storing in as
Names of created variables: PayLevelDetails
Json Path expressions: $.payLevels[${WinSpoke}]
However i am getting error as -
JSONPostProcessor: Error processing JSON content in Pay Level Details
JSON Extractor, message: Could not parse token starting at position
11. Expected ?, ', 0-9, *
Can someone help me in pointing where i might have gone wrong ?
Your setup should work just fine given you have ${WinSpoke} variable defined, you can double check its value using Debug Sampler and View Results Tree listener combination
Also be aware that PostProcessors are being executed upside down so make sure that the JSON Extractor which extracts your WinSpoke variable is above the one which is referencing the variable.

extract the a field value with same name from JSON using 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

In jmeter : how to extract values from two different json response and use that extracted values as a parameter for new http request

In jmeter: I’m using two http requests in one thread group, so I’m getting two response from those http requests.
I need ‘member id’ from one response and some string(digest) from other response, in order to create third http request.
I have extracted 'member id' by using this regular expression: {"Id":(.+?)}
which return me correct member id.
Response from 2nd request is string(digest) : "G9V6Su9PESaobcInErdD7Y8OKNo="
I added one more regular expression to extract this string : "(.+?)"
I have added two debug sampler as I'm using two regular expression extractor.
then I pass extracted values 'member id' and string(digest) as a parameter to third http request.
When I run it I'm getting error, my 3rd http request failed.
It's failing to pass extracted 'member ID', but its correctly pass string(digest)
In first debug sampler: its showing correct extracted 'Member ID' but some different values for digest field.
In 2nd debug sampler: its showing correct extracted 'digest' field but some different value for 'Member ID'.
I’m doing it all under one thread group
I'm new to jmeter, I don’t know whether it is possible to extract field from two different response and use as parameter to create new http request.
if it possible how to do it please help me.
Thanks in advance.
I believe that it's due to including quotation marks (and who knows what else) into the "Id" regular expression, you need to surround it with quotes like:
{"Id":"(.+?)"}
Also the better way of working with JSON data is JSON Path Extractor which is available via JMeter Plugins project. See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") for more information on installation, usage, syntax, etc.

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.

JSON Path Extractor in JMeter

I am new to jmeter. Can anyone help me to use a response object of one request to be passed as a request header of next HTTP request ?
Let me explain.
I am getting an access token along with the response of login in my app:
{: "responseCode":18, : "message":"Successfully logged in.", : "responseObject":"8zWExE4eSdhcJDwnW9MgIw=="}
No I want to use this access token (8zWExE4eSdhcJDwnW9MgIw) as one of the parameter of next request.
I used JSON Path Extractor for this.But its not working.
I am using JSON Path Extractor as well and it works great if it is properly configured.
Just put it into request and fill fields:
Variable Name: access_token (or any other you want to use later in request like this ${access_token})
JSON Path: responseObject should be enough if the JSON you pasted is full response (thjose additional colons are just some mistakes when copy-pasting or the JSON is corrupted?)
Default Value: I always use some value like 'NotUpdated!' here so I can assert in the next step or at least see it easily in request.
Not seeing the full response it is quote hard to come up with a correct JSON Path expression.
Given what you posted it should be something like $.responseObject
See JSON Path Syntax guide for queries syntax examples and Using the XPath Extractor in JMeter (scroll down to "Parsing JSON") for plugin installation instructions and XPath to JSON syntax mapping.
Just in case anybody would face an issue with multiple variable extractions using JSON Extractor (like me), make sure to:
List the names of variables/path expressions/default values using a semicolon as a separator.
Provide default values for every variable.
The second point is apparently required, and I only found out about it from this
Medium post.

Resources