I'm using SoapUI to test REST webservices and I'm stuck on an issue.

I have a json object, called coverages, which consists of one or more other objects, it looks something like this (example with 2 coverages):

"coverages" : [
   "CovNr" : 123,
   "CovDesc" : "My coverage" 
   "CovNr" : 456,
   "CovDesc" : "Another coverage"

The thing is, sometimes there is one coverage, and sometimes there are multiple. This means I need the coverages object to be variable, and have either one or more coverages as its body, depending on # of coverages.

Since the number of coverages isn't always the same I can't use properties for the CovNr and CovDesc attributes. Also I can't just always add like three and leave two empty if only one is used (can't have empty attributes).

I tried to set a coverages property using groovy script, which consisted of the entire body of the coverages object, but that didn't work (I'm guessing the editor can't parse an entire part of a request from a property).

Example of what I tried:

in groovy:

def coverages = "[   {   "CovNr" : 123,   "CovDesc" : "My coverage"    },   {   "CovNr" :456,   "CovDesc" : "Another coverage"   }]" 
testRunner.testCase.setPropertyValue("coverages", coverages)

in request body:

"coverages" : "$(#TestCase#coverages)",

This didn't work.

Is there another way to add a variable number of coverages to my request body?

1 Answer 1


The issue you are having is that your parameter is a String instead of a json object.

In your groovy code: import groovy.json.JsonBuilder

def backToJson = new JsonBuilder(coverages).toPrettyString();
return backToJson

In your request body: grab the result of your groovy testStep like this:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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