Parses response body as JSON and returns an array
Result is cached internally

@throws Exception

@return array
514101
public function jsonArray()
    {

        if (!$this->isContentType('application/json')) {
            throw new Exception('Response is not JSON');
        }

        if (empty($this->_jsonAsArray)) {
            $this->_jsonAsArray = Utils::json_parse($this->text(), true);
        }

        return $this->_jsonAsArray;

    }
993296
public function json()
    {
        $json = json_decode($this->getBody(), true);
        if ($json === null) {
            throw new RuntimeException(sprintf(
                "Can't decode response as JSON: %s",
                function_exists('json_last_error_msg')?
                    json_last_error_msg():
                    'Error code '.json_last_error()
            ));
        }
        return $json;
    }
1351311
public function toArray()
    {
        if ($this->getResponseType() == 'application/json')
        {
            $response = $this->convertJsonToArray($this->getBody());
        }
        elseif ($this->getResponseType() == 'application/binary')
        {
            $response = $this->convertSerializedToArray($this->getBody());
        }
        else
        {
            $response = null;
        }

        if ( ! is_array($response))
        {
            $this->throwResponseConversionException();
        }

        return $response;
    }
933480
public function processRequest($body)
    {
        $body = @json_decode($body);

        if ($body === null or $body === false) {
            throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
        }

        if (empty($body->errors)) {
            return $this->Object->loadFromArray($body->data[0]);
        }

        $ResponseError = new Common\ResponseError($body);
        throw new Exceptions\RequestException($ResponseError->getErrorString());
    }
1333286
public function getJson()
    {
        if (stripos($this->getHeader('content-type'), '/json') !== false) {
            return json_decode($this->body, true);
        } else {
            return false;
        }
    }
59900
private function interpretResponseJSON()
    {
        $this->debug_echo("\n\nResponse (json):\n");
        $this->debug_print_r($this->state['response']['body_raw']);

        // Convert response from json to array format if required
        if ($this->config['dataFormat'] == 'array') {
            try {
                $this->state['response']['body'] = json_decode(
                    $this->state['response']['body_raw'],
                    true
                ); 
            } catch (Exception $e) {
                $msg = 'Invalid response body from API: '.$this->state['response']['body_raw']
                     . '(HTTP response code was '.$this->state['response']['code'].')';
                throw new ApiException($msg, $this->state);
            }
            $this->debug_echo("\n\nResponse (array):\n"); 
            $this->debug_print_r($this->state['response']['body']); 
        } else {
            $this->state['response']['body'] = $this->state['response']['body_raw'];
        }

        if ($this->state['response']['code'] < 200 ||
            $this->state['response']['code'] >= 300
        ) {
            $this->handleHttpError();
        }

        return $this->state;
    }
452154
private function parse($body)
    {
        $result = array();
        $data = json_decode($body);

        $response = is_array($data->response) ? new \stdClass : $data->response;
        if (null == $response) {
            $response = $data;
        }
        $response->errors = $data->errors;
        $response->test = isset($data->test) ? $data->test : $response->test;

        if ($data->successful == true) {
            if ((isset($response->authorized)
                && $response->authorized == true)
                || (isset($response->id)
                && $response->id !== null)
            ) {
                $response->authorization_id = isset($response->id)
                    ? $response->id
                    : $response->token;
            } else {
                $response->authorization_id = null;
            }

            $response->success = true;
        } else {
            $response->success = false;
            $response->authorization_id = null;
        }

        $response->message = isset($response->message) ? $response->message : $data->errors;

        return (array) $response;

    }
1311731
public function jsonSerialize(): array
    {
        $instruction = ['type' => $this->type];

        if ($this->type !== self::TYPE_NOOP) {
            $instruction = array_merge($instruction, [
                'name' => $this->name,
                'catched' => $this->shouldCatchErrors,
            ]);

            if ($this->type !== self::TYPE_GET) {
                $instruction['value'] = $this->value;
            }

            if ($this->resource !== null) {
                $instruction['resource'] = $this->resource;
            }
        }

        return $instruction;
    }
265753
protected function processResponse()
    {
        $body = $this->response->getBody();

        // Look for UTF-8 BOM and remove.
        if (0 === strpos(bin2hex(substr($body, 0, 4)), 'efbbbf')) {
            $body = substr($body, 3);
        }

        $parsedResponse = \json_decode($body);

        // Test if return a valid JSON.
        if (JSON_ERROR_NONE !== json_last_error()) {
            $message = function_exists('json_last_error_msg') ? json_last_error_msg() : 'Invalid JSON returned';
            throw new HttpClientException(
                sprintf('JSON ERROR: %s', $message),
                $this->response->getCode(),
                $this->request,
                $this->response
            );
        }

        $this->lookForErrors($parsedResponse);

        return $parsedResponse;
    }
580568
public function bodyToArray()
    {
        // Getting response content
        $jsonContent = $this->response->getContent();

        // Wrapping it into a Json reader object and convert it to array
        $jsonReader = new Json();
        return $jsonReader->fromString($jsonContent);
    }
199340
public function getParsedResponse()
    {
        // We first get an array representing the response
        $rawData = $this->bodyToArray();

        // If we have a wrapper response object initialized in the current ActionResponse object, then we return it.
        if ($this->responseWrapper instanceof Wrapper\ResponseWrapperInterface) {
            $this->responseWrapper->init($rawData, $this);
            return $this->responseWrapper;
        }
        return $rawData;
    }
164807
protected function parseBody(): array
    {
        if ($this->getRequest()->headers->get('Content-Type') === 'application/json') {
            $dataCollection = json_decode($this->getRequest()->getContent(), true);
        } else {
            if ($this->getRequest()->isMethod('POST')) {
                $dataCollection = array_merge(
                    $this->getRequest()->request->all(),
                    $this->getRequest()->files->all()
                );
            } else {
                parse_str($this->getRequest()->getContent(), $dataCollection);
            }
        }

        return $dataCollection;
    }
56615
public function getJson()
    {
        if (empty($this->json_loaded)) {
            if ($this->getBody() && $this->isJson()) {
                $this->json = json_decode($this->getBody(), true);

                if (json_last_error()) {
                    throw new RuntimeException('Failed to parse JSON. Reason: ' . json_last_error_msg());
                }
            }

            $this->json_loaded = true;
        }

        return $this->json;
    }
1065395
public function jsonSerialize()
    {
        return [
            'host' => $this->host,
            'uri' => $this->uri,
            'method' => $this->method,
            'headers' => $this->headers,
            'body' => $this->body
        ];
    }
1211322
protected function parseJsonBody(ServerRequestInterface $request)
    {
        $body = $request->getBody()->__toString();
        if ($request->hasHeader('Content-Encoding') && 'base64' === $request->getHeader('Content-Encoding')) {
            $body = base64_decode($body, true);
        }

        $bodyJson = @json_decode($body, true);
        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new \Exception(json_last_error_msg());
        }

        return $bodyJson;
    }
925059
public function getResponse()
    {
        $this->execute();
        
        switch ($this->def['dataType']) {
            case 'array':
                $result = static::toArray();
                break;
            case 'object':
            case 'json':
                $result = static::toJson();
                break;
            default:
                $result = $this->getErrorString() ? : $this->responseText;
        }
        
        return $result;
    }
144875
public function parse()
    {
        /*
         * If the object has already been parsed in this request return the cached data.
         */
        if (array_key_exists($this->filePath, self::$cache)) {
            self::$cache[$this->filePath]['source'] = 'request-cache';
            return self::$cache[$this->filePath];
        }

        /*
         * Try to load the parsed data from the cache
         */
        $path = $this->getCacheFilePath();

        $result = [
            'filePath' => $path,
            'className' => null,
            'source' => null,
            'offset' => 0
        ];

        /*
         * There are two types of possible caching scenarios, either stored
         * in the cache itself, or stored as a cache file. In both cases,
         * make sure the cache is not stale and use it.
         */
        if (is_file($path)) {
            $cachedInfo = $this->getCachedFileInfo();
            $hasCache = $cachedInfo !== null;

            /*
             * Valid cache, return result
             */
            if ($hasCache && $cachedInfo['mtime'] == $this->object->mtime) {
                $result['className'] = $cachedInfo['className'];
                $result['source'] = 'cache';

                return self::$cache[$this->filePath] = $result;
            }

            /*
             * Cache expired, cache file not stale, refresh cache and return result
             */
            if (!$hasCache && filemtime($path) >= $this->object->mtime) {
                $className = $this->extractClassFromFile($path);
                if ($className) {
                    $result['className'] = $className;
                    $result['source'] = 'file-cache';

                    $this->storeCachedInfo($result);
                    return $result;
                }
            }
        }

        $result['className'] = $this->rebuild($path);
        $result['source'] = 'parser';

        $this->storeCachedInfo($result);
        return $result;
    }