Forum Discussion

jmahant's avatar
jmahant
Occasional Contributor
7 years ago

Customize the number of key value pairs in a request based on parameter value.

I have a patch request which can be used for multiple categories (as parameter) as following PATCH {URL}/categories/<CategoryName>/values  [{ "name": "<Para1_Name>", "value": "<Para1_value>" ...
  • Radford's avatar
    7 years ago

    I've done this but in my case it was name/value pairs in XML for a SOAP service, from your data I assume you have JSON data for a REST request.

     

    This is just a high level overview of what I would do, all within a groovy test step before your requst test step:

     

    1. Get you JSON data from your REST request, easiest way via the GetData functionality.
    2. Use the JsonSlurper to convert your data to a Groovy object.
    3. Manipulate you data to add and remove the name value pairs via GPath expressions.
    4. Use the JsonOutput to convert you Groovy JSON objects back to JSON data string.
    5. Update your REST request with your new data.