public function writeJson(IHttpResponseMessage $response, array $content): void
    {
        $json = json_encode($content);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new InvalidArgumentException('Failed to JSON encode content: ' . json_last_error_msg());
        }

        $response->getHeaders()->add('Content-Type', 'application/json');
        $response->setBody(new StringBody($json));
    }