I finally found a way to do that. Thanks to Rajeev KR answer which drive me to the solution
The hostArray string has to be converted to JSON and it can be done using with a type conversion to json https://github.com/karatelabs/karate#type-conversion
# sample of hostsArray
* def hostsArray = '[{"hostid": "1234"},{"hostid": "4567"}, {"hostid": "9865"}]'
* json hostArrayJson = hostsArray
* def myjson =
"""
{
"key1": "val1",
"params" : {
"key2": "val2",
"hosts" : '#(hostsArrayJson)'
}
"""