garima
garima

Reputation: 111

Dynamic values with in json file upload - jmeter

I am trying to POST JSON data using HTTP POST sampler in Jmeter. My data has few values which need to be passed based on results from previous samplers. Below is the sample data and I need is, last name and date from a previous GET Response.

{"people":{"primaryPerson":{"id":"1234","date":"2018-02-13",firstName":"Mr","lastName":"apple-eye","birthday":"1980-1-1","gender":"MALE","personType":"PRIMARY"}}

I have json extractors in the previous sampler to extract all 3 values but I don't know how to use them with body data upload. I am using {__FileToString(${__eval(${fileName})},,)} to upload the above data.

In short, I need to know how I can replace ID, LASTNAME and DATE using the previous sampler extracted data when I am passing data in a file.

Upvotes: 1

Views: 2010

Answers (1)

Dmitri T
Dmitri T

Reputation: 168217

  1. Amend your file to look like:

    {
      "people": {
        "primaryPerson": {
          "id": "${foo}",
          "date": "${bar}",
          "firstName": "Mr",
          "lastName": "${baz}",
          "birthday": "1980-1-1",
          "gender": "MALE",
          "personType": "PRIMARY"
        }
      }
    }
    
  2. Amend your __FileToString() and __eval() functions combination to look like

    ${__eval(${__FileToString(request.json,,)})}
    
  3. Replace foo, bar, baz with actual JMeter Variables Reference Names and request.json with relative or full path to your JSON file (modified as per point one)

More information: Here’s What to Do to Combine Multiple JMeter Variables

Upvotes: 3

Related Questions