在Slim Framework中使用JSON流进行响应

I need somehow to make a response ->withHeader('Transfer-Encoding', 'chunked') from my API, but as i understood it requires stream in the response body. How can i turn my key-value array into the JSON stream and respond with it?

Now, my code looks like:

        return $response->withHeader('Connection', 'close')
                ->withHeader('Pragma', 'no-cache')
                ->withHeader('Content-type', 'application/json;charset=utf8')
                ->withHeader('Access-Control-Allow-Origin', '*')
                ->withoutHeader('Content-Length')
                ->withHeader('Transfer-Encoding', 'chunked')
                ->withStatus(200)
                ->withJson($resp);

where $resp is my array. But it won't work...