diff --git a/src/Context/WebApiContext.php b/src/Context/WebApiContext.php index f21b24b..cbda063 100644 --- a/src/Context/WebApiContext.php +++ b/src/Context/WebApiContext.php @@ -265,13 +265,23 @@ public function printResponse() { $request = $this->request; $response = $this->response; + $contentType = $response->getHeader('Content-Type'); + $body = $response->getBody(); + + switch($contentType) { + case 'application/json': + $formattedJson = json_encode(json_decode($body), JSON_PRETTY_PRINT); + if ($formattedJson) { + $body = $formattedJson; + } + } echo sprintf( "%s %s => %d:\n%s", $request->getMethod(), $request->getUrl(), $response->getStatusCode(), - $response->getBody() + $body ); }