How to add multiple filter in Search template

Hi,
I am trying to create search template which will support the multiple term filter for different fields. I have created search template but facing issue for adding comm after each filter. in current case if all the filter provide the it work fine, if first only provided or last filter value is not provided then it will throw error. please let me know if i am missing anything here.

Below is my Search template:

POST product/_search/template
{
  "source": """{
    "size": "{{size}}",
    "from": "{{from}}",
    "query": {
      "bool": {
        "must": [
          {
            "query_string": {
              "fields": [
                "product_id"
              ],
              "query": "{{query}}"
            }
          }
        ],
        "filter": [
          {{#brand}}
          {
            "terms": {
              "brand.keyword": 
                {{#toJson}}brand{{/toJson}}
            }
          },{{/brand}}{{#country}}
          {
            "terms": {
              "country.keyword": 
                {{#toJson}}country{{/toJson}}
            }
          },{{/country}}{{#language}}
          {
            "terms": {
              "Language.keyword": 
                {{#toJson}}language{{/toJson}}
            }
          }{{/language}}
        ]
      }
    }
  }""",
  "params": {
    "query": "101",
    "size": "10",
    "from": "0",
    "brand": [
      "dove",
      "shampoo"
    ],
    "country": [
      "UK"
    ],
    "language": [
      "English"
    ]
  }
}

Here, if i remove language from the params and only provide brand in params then it is throwing below error because of the comm issue in filter context. i am not sure how to handle comma in search template.

 {
  "error" : {
    "root_cause" : [
      {
        "type" : "x_content_parse_exception",
        "reason" : "[32:21] [bool] failed to parse field [filter]"
      }
    ],
    "type" : "x_content_parse_exception",
    "reason" : "[32:21] [bool] failed to parse field [filter]",
    "caused_by" : {
      "type" : "json_parse_exception",
      "reason" : "Unexpected character (']' (code 93)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (StringReader); line: 32, column: 22]"
    }
  },
  "status" : 400
}

is there anyone who can help me on this?