HTTP request body in JMeter
{"guid":"3659174697251947","syncId":"${C_SyncID1}:8:9474","changes":{"_CreatedDate":{"value":1674476500333},"IsDeleted":{"value":false},"CheckinQuantityEdit":{"value":"0"},"OrderQuantity":{"value":"1"},"LineStatus":{"value":"Purchaseorder"},"CheckinPrice":{"value":"65.62"},"ProductName":{"value":null},"LineNumber":{"value":"1"},"RequiresMobileSync":{"value":true},"CheckInQuantity":{"value":"1"},"NativeMobile.OrderItem_DynamicCustomerProduct":{"value":null},"NativeMobile.OrderItem_Order":{"value":"26177172834105120"},"NativeMobile.OrderItem_CustomerProduct":{"value":"28710447624499413"},"isDeletedOnMobileDevice":{"value":false},"ProductCode":{"value":null}}},
for the above request we need to capture - NativeMobile.OrderItem_Order":{"value":"26177172834105120 and -- guid":"3659174697251947", for the product NativeMobile.OrderItem_CustomerProduct":{"value":"28710447624499413"},
Response 1
from the below response we need to capture order guid 26177172834105120 based on OrderNumber":{"value":"J40000099VN0001"}
So if the OrderNumber":{"value":"J40000099VAN0001" guid will be guid":"26177172834105120"
"OrderNumber":{"value":"J40000099VAN0001"},"JobNumber":{"value":"jbdemo"},"FulfilmentMethod":{"value":"Collection"},"DeliveryAttended":{"value":null},"OrderAPI":{"value":"ICON"},"CustomerOrderTypeAtSubmission":{"readonly":true,"value":"JobOrder"},"OrderDateSubmitted":{"value":1674476500321},"SubOrderType":{"value":null},"NativeMobile.Order_OrderingEntity":{"value":"31806672368314430"},"ICONAPIStatus":{"value":null},"OrderPostStatus":{"value":"Success"},"isDeletedOnMobileDevice":{"value":false},"OrderNumberInteger":{"value":"99"}},"guid":"26177172834105120","hash":"kxniswgHZITElfZ5lHihQiGnuLsuLM4e407HOTy8ih0=","
Response 2
If NativeMobile.OrderItem_Order":{"value":"26177172834105120" and
NativeMobile.OrderItem_CustomerProduct":{"value":"28710447624499413"}
Then only guid will be guid":"3659174697251947"
{"changes":{},"commits":[],"committedObjectsOmitted":false,"deletes":[],"hasMoreItems":false,"newpersistable":[],"objects":[{"attributes":
{"ProductCode":{"value":null},"NativeMobile.OrderItem_Order":{"value":"26177172834105120"},"NativeMobile.OrderItem_DynamicCustomerProduct":{"value":null},"RequiresMobileSync":{"value":false},"AmountMatched":{"readonly":true,"value":"0"},"CheckInQuantity":{"value":"1"},"LineNumber":{"value":"2"},"CheckinPrice":{"value":"91.55"},"LineStatus":{"value":"Purchaseorder"},"ProductName":{"value":null},"isDeletedOnMobileDevice":{"value":false},"OrderQuantity":{"value":"1"},"CheckinQuantityEdit":{"value":"0"},"NativeMobile.OrderItem_CustomerProduct":{"value":"28710447624499413"},"IsDeleted":{"value":false},"_CreatedDate":{"value":1674476500342},"FullyMatched":{"readonly":true,"value":false}},"guid":"3659174697251947","hash":"Brd19q5Z1yYq0L8U1noeIsvcthz89N/pvTg/5EqeBnY="
Please help me out her to capture the values 3659174697251947 and 26177172834105120
You can extract guid for the NativeMobile.OrderItem_CustomerProduct==28710447624499413 using JSON Extractor, the relevant JSONPath query will be:
$.[?(#.changes.['NativeMobile.OrderItem_CustomerProduct'].value == '28710447624499413')].guid
Pretty much similar you can get the NativeMobile.OrderItem_Order
$.changes[?(#.['NativeMobile.OrderItem_CustomerProduct'].value == '28710447624499413')].['NativeMobile.OrderItem_Order'].value
With regards to responses 1 and 2 - I cannot help you because your JSON is incomplete.
More information:
JSONPath Operators
How to Use the JSON Extractor For Testing
I am getting a response in form of serialized json format for an api request as below
{"Data":"{\"orderId\":null,\"Tokens\":{\"Key\":\"abcdefgh123456\",\"Txnid\":\"test_5950\"}","success":true,"Test":"success"}
I want to extract Key value in Jmeter and I have to use into next request. Can someone help me on extracting the value?
Your JSON seems incorrect. The valid JSON should be like:
{
"Data":{
"orderId":null,
"Tokens":{
"Key":"abcdefgh123456",
"Txnid":"test_5950"
},
"success":true,
"Test":"success"
}
}
Add a JSON Extractor to the request from where you want to extract the Key value.
assign a variable name, i.e key
JSON Path Expression will be : .Data.Tokens.Key
use the extracted value as ${key} into the next request.
If your JSON really looks exactly like you posted the most suitable Post-Processor would be Regular Expression Extractor
The relevant regular expression would be something like:
"Key"?\s*:?\s*"(\w+)"
where:
``?\s*` - arbitrary number of whitespaces (just in case)
\w - matches "word" character (alphanumeric plus underscores)
+ - repetition
() - grouping
More information:
Using RegEx (Regular Expression Extractor) with JMeter
Perl 5 Regex Cheat sheet
JMeter: Regular Expressions
i'am using jmeter "Regular Expression Extractor",my response looks as below
[{"#class":"com.test.dto.BoardDTO",
"ReadOnly":false,
"author":"John",
"id":"89BC331D723F",
"isPublic":false
},
{"#class":"com.test.dto.BoardDTO",
"ReadOnly":false,
"author":"Alex",
"id":"FTH7JBDRF567",
"Public":false
}]
I need to extract all IDs of class:"com.test.dto.BoardDTO" in this case "89BC331D723F" and "FTH7JBDRF567"
Any proposition please !
You should use JSON Extractor instead of regular expression extractor
Add a JSON Extractor and fill in the fields as below
JSON path expression: $.[*][?(#.#class == "com.test.dto.BoardDTO")].id
Match Numbers: -1
This will return all IDs where #class value was com.test.dto.BoardDTO. You can validate it using View Results Tree & Debug Sampler combination.
I am using Jmeter for performance testing and stuck at following point:
I am getting a JSON response from Webapi as follows:
PersonInfoList:
Person
[0]
{
id: 1
name: Steve
}
[1]
Person
{
id: 2
name: Mark
}
I need to get the ids based on the count of this JSON array and create a comma separated string as ("Expected value" = 1,2)
I know how to read a particular element using JSON Post processor or Regex processor but am unable to loop through the array and create a string as explained so that I can use this value in my next sampler request.
Please help me out with this: I am using Jmeter 3.0 and if this could be achieved without using external third party libs that would be great. Sorry for the JSON syntax above
Actually similar functionality comes with JSON Path PostProcessor which appeared in JMeter 3.0. In order to get all the values in a single variable configure JSON Path PostProcessor as follows:
Variable Names: anything meaningful, i.e. id
JSON Path Expressions: $..id or whatever you use to extract the ids
Match Numbers: -1
Compute concatenation var (suffix _ALL): check
As a result you'll get id_ALL variable which will contain all JSON Path expression matches (comma-separated)
More "universal" answer which will be applicable for any other extractor types and in fact will allow to concatenate any arbitrary JMeter Variables is using scripting (besides if you need this "expected value and parentheses)
In order to concatenate all variables which names start with "id" into a single string add Beanshell PostProcessor somewhere after JSON Path PostProcessor and put the following code into "Script" area
StringBuilder result = new StringBuilder();
result.append("(\"Expected value\" = ");
Iterator iterator = vars.getIterator();
while (iterator.hasNext()) {
Map.Entry e = (Map.Entry) iterator.next();
if (e.getKey().matches("id_(\\d+)")) {
result.append(e.getValue());
result.append(",");
}
}
result.append(")");
vars.put("expected_value", result.toString());
Above code will store the resulting string into ${expected value} JMeter Variable. See How to Use BeanShell: JMeter's Favorite Built-in Component article for more information regarding bypassing JMeter limitations using scripting and using JMeter and Java API from Beanshell test elements.
Demo:
The response I get back from a post is just a plain text guid seen here I'd like to pull this guid and use it in a variable for my following Get statement:
post response data
And I've tried a bunch of configurations in my regular expression extractor.
But it just ends up pulling Null when what I want is that guid.
Null
I'm new to jmeter - so thank you in advance for the help.
If you need the whole response use the following Regular Expression Extractor configuration:
Reference Name: response
Regular Expression: (?s)(^.*)
Template: $1$
As per How to Extract Data From Files With JMeter guide:
() = grouping
(?s) = single line modifier
^ = line start
. = wild-card character
* = repetition
So it will return the whole response.