2
votes

I am new to Jmeter searched a lot but unable to find solution.A little help is appreciated. Thanks.

Problem - In my http request I have below body My actual request is

{
  "Summary": {
    "source": {
      "Name": "Phones",
      "dataSource": "Oracle",
      "dbType": "${Value}",
      "sid": "${sUsername}",
      "spswd": "${sPassword}",
      "aut": "${win}",    
      "PrjName": "${sourceprojectName}"
    },
    "Destination": {
      "dataSource": "SQL",
      "projectName": "${destprojectName}",
      "server": "${urlValue}"
      "destUsrName": "${dUsername}",
      "destPswd": "${dPassword}",
    },
    "Notifiction": "True",
    "Time": "dd:mm:yy",
    "Config": true,
    "Properties": [
      {
        "type": "iPhone",
        "ids": [
          {
            "id": "f132d",
            "Guid_id": null
          },
          {
            "id": "6332569",
            "Guid_id": null
          },
          {
            "id": "5b55d2f",
            "Guid_id": null
          },
          {
            "id": "81f1330",
            "Guid_id": null
          }
        ]
      }
    ]
  },
  "Execute": true
}

The id in the request is dynamic so I want to paramterize it. using Json extractor I got these Id's from another response. All these Id's are in array. id=["f132d","6332569","5b55d2f","81f1330"]

Now i dont know how to put these id into my request body. Please assist

1

1 Answers

1
votes

You can generate required request body as follows:

  1. Add JSR223 PreProcessor as a child of the request which body you want to make dynamic
  2. Put the following code into "Script" area:

    def ids = new groovy.json.JsonSlurper().parseText(vars.get('id'))
    def builder = new groovy.json.JsonBuilder()
    builder(Properties:[ [type: "iPhone", ids: ids.collect {[id: it,"Guid_id": null]}]])
    sampler.getArguments().removeAllArguments()
    sampler.addNonEncodedArgument('',builder.toPrettyString(),'')
    sampler.setPostBodyRaw(true);
    

More information: