src/Http/Formatting/ResponseFormatter.php
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));
    }
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));
    }
Writes JSON to the response

@param IHttpResponseMessage $response The response to write to
@param array $content The JSON to write
@throws InvalidArgumentException Thrown if the input JSON is incorrectly formatted
@throws RuntimeException Thrown if the content type header's hash key could not be calculated