code: private function decodeResponse(Response $response)
      {
          $data = json_decode($response->getBody()->read($response->getBody()->getSize()), true);
          if (json_last_error() !== JSON_ERROR_NONE) {
              throw new ClientException('Unable to parse response body into JSON: ' . json_last_error());
          }
  
          return $data === null ? array() : $data;
      }
docs: Decode a JSON response.
  @param Response $response
  @return array Parsed response.
  @throws ClientException In case response cannot be read properly.