Parse JSON response to array.

@param \GuzzleHttp\Message\Response|\GuzzleHttp\Psr7\Response $rawResponse

@return array
965443
protected function responseToArray($rawResponse)
    {
        $body = (string) $rawResponse->getBody();
        $code = $rawResponse->getStatusCode();

        if ($code !== 204) {
            $response = json_decode($body, true);
            if (json_last_error() !== JSON_ERROR_NONE) {
                $response = ['body' => trim($body)];
            }
        } else {
            $response = '';
        }

        return (200 <= $code && $code <= 299 ? $response : ($response ?: $this->jsonError($rawResponse)))
            ?: [];
    }
1041437
def _from_json_array_nested(cls, response_raw):
        

        json = response_raw.body_bytes.decode()
        obj = converter.json_to_class(dict, json)
        value = converter.deserialize(cls, obj[cls._FIELD_RESPONSE])

        return client.BunqResponse(value, response_raw.headers)
321032
protected function parseFiles(array $raw) {
		if(isset($raw['name']) && isset($raw['type']) && isset($raw['tmp_name']) && isset($raw['error']) && isset($raw['size'])) {
			if(is_array($raw['name'])) {
				$name = $this->convertTo('name', $raw['name']);
				$type = $this->convertTo('type', $raw['type']);
				$tmp_name = $this->convertTo('tmp_name', $raw['tmp_name']);
				$error = $this->convertTo('error', $raw['error']);
				$size = $this->convertTo('size', $raw['size']);

				$files = $this->mergeAll($name, $type, $tmp_name, $error, $size);

				foreach($files as $k=>$v)
					$files[$k] = \Asgard\Http\HttpFile::createFromArray($v);
			}
			else
				$files = \Asgard\Http\HttpFile::createFromArray($raw);
		}
		else {
			foreach($raw as $k=>$v)
				$raw[$k] = $this->parseFiles($v);
			$files = $raw;
		}

		return $files;
	}
1030211
protected function createResponse($rawResponse)
    {
        $response = new Response();

        $headerSize = curl_getinfo($this->handle, CURLINFO_HEADER_SIZE);
        $rawHeaders = trim(substr($rawResponse, 0, $headerSize));
        $rawHeadersArray = explode("\r\n\r\n", $rawHeaders);

        if (!empty($rawHeadersArray)) {
            $headerLines = explode("\r\n", $rawHeadersArray[0]);
            foreach ($headerLines as $headerLine) {
                if (stripos(trim($headerLine), 'http', 0) === 0) {
                    if (preg_match('/^http\/((\d*[.])?\d+)\s+(\d+)\s+([a-z]+)/i', trim($headerLine), $matches)) {
                        $response = $response->withStatus($matches[3], $matches[4])
                            ->withProtocolVersion($matches[1]);
                    }
                    continue;
                }

                $header = explode(':', $headerLine, 2);
                $name = trim($header[0]);
                $value = trim($header[1]);

                if ($response->hasHeader($name)) {
                    $response = $response->withAddedHeader($name, $value);
                } else {
                    $response = $response->withHeader($name, $value);
                }
            }
        }

        $content = substr($rawResponse, $headerSize);
        $response->getBody()->write($content);
        $response->getBody()->rewind();

        return $response;
    }
1337987
protected function parseResponseHeadersAsArray($headers)
    {
        if (empty($headers)) return [];

        $headersArray = [];

        foreach (preg_split('#[\r\n]+#', $headers) as $headerString) {

            if ( ! preg_match('#^\s*(?<name>.*?)\s*:\s*(?<value>.*)\s*$#', $headerString, $matches)) continue;

            $headersArray[ $matches['name'] ] = $matches['value'];
        }

        return $headersArray;
    }
661357
private function parseHttpHeaders($rawHeaders) {
		// ref/credit: http://php.net/manual/en/function.http-parse-headers.php#112986
		$headers = array();
		$key = '';

		foreach (explode("\n", $rawHeaders) as $h) {
			$h = explode(':', $h, 2);

			if (isset($h[1])) {
				if (!isset($headers[$h[0]])) {
					$headers[$h[0]] = trim($h[1]);
				} elseif (is_array($headers[$h[0]])) {
					$headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1])));
				} else {
					$headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1])));
				}

				$key = $h[0];
			} else {
				if (substr($h[0], 0, 1) === "\t") {
					$headers[$key] .= "\r\n\t".trim($h[0]);
				} elseif (!$key) {
					$headers[0] = trim($h[0]);
				}
				trim($h[0]);
			}
		}

		return $headers;
	}
157164
public function collect($rawData)
    {
        $result = array();

        foreach ($this->collectors as $name => $collectorInstance)
        {
            $result[$name] = $collectorInstance->collect($rawData);
        }

        return $result;
    }
598786
def parse_json(raw_json):
        
        result = json.loads(raw_json)

        if 'results' in result:
            result = result['results']

        return result
503619
public function parse(CurlResponse $curlResponse)
    {
        $responseBody = $curlResponse->getBody();

        $contentType = $curlResponse->info()->getContentType();
        $responseType = $this->getResponseType($contentType);
        $responseCharset = $this->getResponseCharset($contentType);

        $httpCode = $curlResponse->info()->getHttpCode();
        $httpMessage = $this->responseCodes->getMessage($httpCode);

        return new Response($responseBody, $responseType, $responseCharset, $httpCode, $httpMessage);
    }
125671
public static function makeFromJson(JsonResponse $json)
    {
        $content = $json->getContent();

        // If the contents of the JsonResponse does not starts with /**/ (typical laravel jsonp response)
        // we assume that it is a valid json response that can be decoded, or we just use the raw jsonp
        // contents for building the response
        if (! starts_with($json->getContent(), '/**/')) {
            $content = json_decode($json->getContent(), true);
        }

        $new = static::create($content, $json->getStatusCode());

        $new->headers = $json->headers;

        return $new;
    }
658765
public function convert(array $rawConfig)
    {
        $return = [];
        foreach ($rawConfig as $key => $value) {
            $return[$key] = $this->getConfigValue($value);
        }

        return $return;
    }
1273664
public function parse($rawBody, $contentType)
    {
        try {
            return Json::decode($rawBody, $this->asArray);
        } catch (\Exception $e) {
            if ($this->throwException) {
                throw new RequestException('Invalid JSON data in request body: ' . $e->getMessage(), [], $e);
            }

            return null;
        }
    }
708665
private function getResponseArray($data, $responseExpectedFormat = 'json')
    {
        $result = $hierarchy = [];
        try {
            switch ($responseExpectedFormat) {
                case 'headers':
                    foreach ($data as $key => $array) {
                        $result[$key] = implode('; ', $array);
                    }
                    break;

                case 'xml':
                case 'html':
                    if (
                        false !== strpos($data, '<')
                        && false !== strpos($data, '>')
                    ) {
                        $doc          = new DOMDocument();
                        $doc->recover = true;
                        $data         = trim($data);
                        // Ensure UTF-8 encoding is handled correctly.
                        if (1 !== preg_match('/^<\??xml .*encoding=["|\']?UTF-8["|\']?.*>/iU', $data, $matches)) {
                            // Possibly missing UTF-8 specification.
                            $opening      = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
                            $replaceCount = 0;
                            $data         = preg_replace(
                                '/^<\??xml(.*)\?*>/iU',
                                $opening,
                                $data,
                                1,
                                $replaceCount
                            );
                            if (!$replaceCount) {
                                // Missing opening XML block entirely.
                                $data = $opening.$data;
                            }
                        }
                        if ('html' == $responseExpectedFormat) {
                            @$doc->loadHTML($data);
                        } else {
                            @$doc->loadXML($data);
                        }
                        $hierarchy = $this->domDocumentArray($doc);
                    }
                    break;

                case 'json':
                    $jsonHelper = new JSONHelper();
                    $hierarchy  = $jsonHelper->decodeArray($data, 'API Response', true);
                    break;

                case 'text':
                    // Handle the most common patterns of a multi-line delimited expression.
                    foreach (explode("\n", $data) as $line) {
                        if (!empty($line)) {
                            foreach ([':', '=', ';'] as $delimiter) {
                                $elements = explode($delimiter, $line);
                                if (2 == count($elements)) {
                                    // Strip outer whitespace.
                                    foreach ($elements as &$element) {
                                        $element = trim($element);
                                    }
                                    unset($element);
                                    // Strip enclosures.
                                    foreach ($elements as &$element) {
                                        foreach (['"', "'"] as $enclosure) {
                                            if (
                                                0 === strpos($element, $enclosure)
                                                && strrpos($element, $enclosure) === strlen($element) - 1
                                            ) {
                                                $element = trim($element, $enclosure);
                                                continue;
                                            }
                                        }
                                    }
                                    unset($element);
                                    list($key, $value) = $elements;
                                    $result[$key]      = $value;
                                    break;
                                }
                            }
                        }
                    }
                    // Fall back to a raw string (no key-value pairs at all)
                    if (!$result) {
                        foreach (explode("\n", $data) as $l => $line) {
                            $result['line '.($l + 1)] = $line;
                        }
                    }
                    break;

                case 'yaml':
                    $yaml = Yaml::parse($data, true);
                    if (is_array($yaml) || is_object($yaml)) {
                        $hierarchy = $yaml;
                    }
                    break;
            }
        } catch (\Exception $e) {
            // Sub-parsing may fail, but we only care about acceptable values when validating.
            // Logging will capture the full response for debugging.
        }

        // Flatten hierarchical data, if needed.
        if ($hierarchy) {
            if (!is_array($hierarchy) && !is_object($hierarchy)) {
                $hierarchy = [$hierarchy];
            }
            $result = $this->flattenStructure($hierarchy);
        }

        // Stringify all values.
        foreach ($result as $key => &$value) {
            if (true === $value) {
                $value = 'true';
            } elseif (false === $value) {
                $value = 'false';
            }
            $value = (string) $value;
        }

        return $result;
    }
1336557
public function parseJsonResponse($jsonResponse = null): self
    {
        if (!is_array($jsonResponse)) {
            throw new RuntimeException('Response must be a scalar value');
        }

        $this->_receipt = $jsonResponse;
        $this->_purchases = [];
        $this->_purchases[] = new PurchaseItem($jsonResponse);

        return $this;
    }
1096810
protected function getResponses(array $executeResponse)
    {
        if (isset($executeResponse['error'])) {
            return array_fill(0, $this->requests->count(), $executeResponse['error']);
        }

        $errors = isset($executeResponse['execute_errors']) ? $executeResponse['execute_errors'] : [];

        return array_map(function ($response) use (&$errors) {
            return $response ?: array_shift($errors);
        }, $executeResponse['response']);
    }
728199
protected static function parseColumns(array $rawColumns, DataTablesWrapperInterface $wrapper) {

        $dtColumns = [];

        foreach ($rawColumns as $current) {

            $dtColumn = static::parseColumn($current, $wrapper);
            if (null === $dtColumn) {
                continue;
            }

            $dtColumns[] = $dtColumn;
        }

        return $dtColumns;
    }
964132
public static function makeFromJson(JsonResponse $json)
    {
        $content = $json->getContent();

        // If the contents of the JsonResponse does not starts with /**/ (typical laravel jsonp response)
        // we assume that it is a valid json response that can be decoded, or we just use the raw jsonp
        // contents for building the response
        if (! Str::startsWith($json->getContent(), '/**/')) {
            $content = \json_decode($json->getContent(), true);
        }

        $new = static::create($content, $json->getStatusCode());

        $new->headers = $json->headers;

        return $new;
    }