I am trying to formulate a template request which can be used via a scenario outline which will be used to test the API without the need for many payloads to be constructed & maintained.
But I've struck a problem when an array is included in the request which contains different optional blocks - that if left empty cause an invalid JSON to be formed and sent.
How can I have an array set correctly (disclude the ",{}" when there is the absence of values from in the scenario outline?
Background: * def template_request = read('./request/request.json')
 Scenario Outline: blah
 * def request_payload = karate.filterKeys(template_request, <request_filter>)
Given request request_payload
When method post
Examples:
  |denominationType1   |amount1|denominationType2 |amount2 |request_filter   |
  |NOTE                |10     |                  |        | 'depositDetail' |
  |NOTE                |10     |COINS             |20      | 'depositDetail' |
                                                                
The request sent from the first row of tbl (which has empty value for denomination type 2 (COINS) is: **See below the second array object which is still set (albeit with no values - which is as per tbl) -> the comma and curly braces , {} which is setting the second array is causing the problem
{
 "depositDetail": {
   "denomination": [
    { 
     "amount": "10",
     "denominationType": "NOTE"
    },
    {
    }
]
}
The request for the second row is fine
{
 "depositDetail": {
   "denomination": [
    { 
     "amount": "10",
     "denominationType": "NOTE"
    },
    {
     "amount": "20",
     "denominationType": "COINS"
    }
]
}
requestTemplate.json
{
 "depositDetail": {
  "denomination": [
   {
    "denominationType": ##(denominationType1),
    "count": ##(count),
    "amount": ##(amount1)
   },
   {
    "denominationType": ##(denominationType2),
    "amount": ##(amount2)
  }
]
} }
I am having no luck with filters or functions - could you please help me.