response->{$name}(...$arguments); } public function json(?string $key = null, $default = null) { if ($this->response->getHeaderLine('content-type') !== 'application/json') { throw new ServerException('The Content-Type of response is not equal application/json'); } $data = json_decode((string) $this->response->getBody(), true); if (! $key) { return $data; } return Arr::get($data, $key, $default); } }