My Json is like below, I want to extract json for all the "code" values and put them with comma separated. **I have almost 250 code values and want them like this
RFI027,RFI037,RFI407,RFI055,RFI457,RFI677,RFI068,RFI086
{
"totalDocs":202,
"recordBatchSize":224,
"listingType":31,
"currentPageNo":1,
"recordStartFrom":18,
"columnHeader":[
{
"id":"0",
"fieldName":"commId",
"isCustomAttributeColumn":false,
"isActive":false
},
{
"id":"24264704",
"function":"",
"funParams":"",
"wrapData":"",
},
{
"code":"RFI027",
"noOfActions":0,
"observationId":0
},
{
"code":"RFI037",
"noOfActions":0,
"observationId":0
},
{
"code":"RFI407",
"noOfActions":0,
"observationId":0
},
{
"code":"RFI055",
"noOfActions":0,
"observationId":0
},
{
"code":"RFI457",
"noOfActions":0,
"observationId":0
},
{
"code":"RFI677",
"noOfActions":0,
"observationId":0
},
{
"code":"RFI068",
"noOfActions":0,
"observationId":0
},
{
"code":"RFI086",
"noOfActions":0,
"observationId":0
},
],
"sortField":"updated",
"sortFieldType":"timestamp",
"sortOrder":"desc",
"editable":true,
"isIncludeSubFolder":true,
"totalListData":0
}
I tried with $..code in Jmeter Json Extractor but it returns only one Value. but I want output like RFI027,RFI037,RFI407,RFI055,RFI457,RFI677,RFI068,RFI086. As I want to pass all values in another request. I have tried with 0,1,2,3 and -1 match no. but it returns only one value, while for -1 it returns ${ref_formCode1}. Appreciate your help. Thank you in advanced.
CodePudding user response:
You can achieve this using a JSR223 post-processer
using the following code, meanwhile notice there are few syntactical errors in your JSON,
Add the JSR223 post-processer
to your request and this will do your ask
import groovy.json.JsonSlurper;
def response = new groovy.json.JsonSlurper().parse(prev.getResponseData());
def CodeFile = '';
response.columnHeader.code.each {
Code->if (Code == null) {}
else {
CodeFile = Code ',' //this will have your code but there will be ',' at the last
}
}
def CodeFileList = CodeFile.subSequence(0, CodeFile.length() - 1) // this will remove the last ,
log.info('CodeFile:' CodeFileList)
vars.put("CodeList",CodeFileList)
CodePudding user response:
You're almost there, you just need to:
- Set "Match No" to
-1
- Tick
Compute concatenation var
box
It will give you the ${ref_formCode1_ALL}
More information: How to Use the JSON Extractor For Testing