Ah well there shouldn't even be any recursion with the <code>$params</code> array. So maybe <code>
json_encode(array_map(function($param) {
    return ! mb_check_encoding($param, 'UTF-8') ? utf8_encode($param) : $param;
}, $params));
</code> should do the trick.