code: protected function sendJson(Response $response, $payload): Response
      {
          $response->getBody()->write(json_encode($payload));
          return $response->withHeader('Content-Type', 'application/json');
      }
docs: Send something as JSON.
  
  @param \Psr\Http\Message\ResponseInterface $response  The response
  @param mixed $payload  The object to serialize
  @return \Psr\Http\Message\ResponseInterface  The JSON response