1

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.

enter image description here

Edit:

After implementing JSR223 post-processer It shows blank field. Here are the screenshots.

enter image description here

enter image description here

enter image description here

2 Answers 2

2

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)

enter image description here

If the code value is inside the data

import groovy.json.JsonSlurper;

def response = new groovy.json.JsonSlurper().parse(prev.getResponseData());
def CodeFile = '';

response.data.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('CodeList:' + CodeFileList)
vars.put("CodeList",CodeFileList)

Usage: Inside request body

enter image description here

enter image description here

Inside the request URL

enter image description here

enter image description here

In another controller,

enter image description here

enter image description here

==========

After edit in the main question:

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for the answer Jyoti Prakash. How do I use 'CodeFileList' in my next http request as input? I have used like ${CodeFileList} this in request but in response it passes the same ${CodeFileList} instead of values.
Please try to use ${__groovy(vars.get('CodeFileList'),)}
I have passed ${__groovy(vars.get('CodeFileList'),)} but it passes blank here.
Could you please paste the request method and how you are using it ?
Added few screenshot for reference
|
1

You're almost there, you just need to:

  1. Set "Match No" to -1
  2. Tick Compute concatenation var box

enter image description here

It will give you the ${ref_formCode1_ALL} JMeter Variable holding all codes matched by you JsonPath query separated by commas:

enter image description here

More information: How to Use the JSON Extractor For Testing

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.