0

Here is the Json Data:

filterKeys":{"${FilterGroup}":["Phenols"]},"lastFilterGroup":"${FilterGroup}"}

I have to extract phenols from the post request for every filter group this value changes.

  • Do you mean a response? If you have a request why would you need to parse anything from it? – Alexey R. Mar 13 '18 at 18:14
  • I am aware of using regular expression for extracting response value in the Response data but I am not sure how to use Regular expression for the json data which is in the POST request. – user31451 Mar 13 '18 at 18:28
  • How do you compose your POST request? JSON data should somehow get to the request body. How does it get there? – Alexey R. Mar 13 '18 at 19:00
  • This is my Body data in the jmeter which is in the Json format {"keyword":"${Keyword}","maxlength":25,"offset":0,"sortKeys":{"ascending":false,"attributeName":"relevance","type":"ATTRIBUTE"},"filterKeys":{"analyte":["Phenols"]},"lastFilterGroup":"analyte"} so this is my request. Based on the selection of filter groups (in this case analyte) the term Phenols changes everytime and I want to extract that value to a regular expression variable. – user31451 Mar 13 '18 at 19:08
0

Since request payloads have to be composed by yourself, it doesn't make much sense to extract data from there. Makes sense, instead, to fill them with data you take/populate from somewhere.

What could easily be done then, is to populate the request body with variables, so your request body may look like this:

{  
   "keyword":"${Keyword}",
   "maxlength":25,
   "offset":0,
   "sortKeys":{  
      "ascending":false,
      "attributeName":"relevance",
      "type":"ATTRIBUTE"
   },
   "filterKeys":{  
      "${filter_key}":[  
         "${filter_value}"
      ]
   },
   "lastFilterGroup":"${filter_key}"
}

And add a JSR223 PreProcessor (using groovy) to that request sampler, where to put values for those variables, like:

vars.put('filter_key', 'analyte');
vars.put('filter_value', 'Phenols');

Otherwise, if you want to extract "analyte" and "Phenol" from that JSON body, given it is a response, you can add a JSON Extractor to the sampler and use the following path expressions

$.filterKeys

to get

[
  {
    "analyte": [
      "Phenols"
    ]
  }
]

and

$.filterKeys.analyte.*
// or
$.filterKeys.${filter_key}.*

to get

[
  "Phenols"
]

or other combinations that you can try out on several websites like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.