Transforms a JSON string to an array.

@param string $string

@throws \RuntimeException

@return array
486962
public static function jsonToArray(string $string): array
    {
        static $jsonErrors = [
            JSON_ERROR_DEPTH => 'JSON_ERROR_DEPTH - Maximum stack depth exceeded',
            JSON_ERROR_STATE_MISMATCH => 'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch',
            JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR - Unexpected control character found',
            JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON',
            JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded',
        ];

        $data = json_decode($string, true);

        if (JSON_ERROR_NONE !== json_last_error()) {
            $last = json_last_error();

            throw new \RuntimeException(
                'Unable to parse JSON data: '
                .(isset($jsonErrors[$last]) ? $jsonErrors[$last] : 'Unknown error')
            );
        }

        return $data;
    }
1342219
public function write($string)
    {
        if (strlen($string) !== $bytesWritten = fwrite($this->getHandle(), $string)) {
            throw new RuntimeException(
                'Buffer could not be written to stream.'
            );
        }

        return $bytesWritten;
    }
778883
protected static function unserialize($string)
    {
        if (is_array($string)) {
            return $string;
        }

        if (($data = unserialize($string)) !== false) {
            return $data;
        }

        return unserialize(stripslashes($string));
    }
805657
public static function toObject($string = '')
    {

        if ($string === '') {
            return new stdClass();
        }


        if (self::isJson($string)) {
            return json_decode($string);
        }


        if (self::isXml($string)) {
            return self::xmlToObject($string);
        }

        $unserialize = self::unserialize($string);
        if ($unserialize === false) {
            return new stdClass();
        }

        if (\is_object($unserialize)) {
            return $unserialize;
        }

        return new stdClass();
    }
344055
public static function decode($string)
    {
        if (!$string) {
            return new ArrayObject();
        }

        try {
            $array = unserialize($string);
        } catch (\Exception $e) {
            throw new PhpException("Serialize Error: " . $e->getMessage());
        }

        if (!is_array($array)) {
            $array = [];
        }

        return ArrayObject::make($array);
    }
913497
public static function jsonDecode($string)
    {
        if ($string) {
            $json = json_decode($string, true);
            // if json_decode failed
            if ($json === null) {
                self::jsonLastError();
            }
            return $json;
        } else {
            return false;
        }
    }
1316271
protected function transformXmlToArray($xmlString)
    {
        if (mb_detect_encoding($xmlString, 'UTF-8', true) === false) {
            $xmlString = utf8_encode($xmlString);
        }

        $xml = simplexml_load_string($xmlString);
        $json = json_encode($xml);

        return json_decode($json, true);
    }
540145
public function decode(string $json): array
    {
        $decoded = \json_decode($json, true);
        if (\json_last_error() !== JSON_ERROR_NONE) {
            throw new DecodingException(\json_last_error_msg(), \json_last_error());
        }
        return $decoded;
    }
1339199
public function parseString($string)
    {
        $string = (string) $string;
        $string = preg_replace_callback("/\\$\{(.*?)\}/",
            function ($k) {
                return $this->get($k[1]);
            }, $string);

        return $string;
    }
179065
public function loadFromString($string)
    {
        $target = array();
        $array = explode(self::SEPARATOR, $string);

        foreach ($array as $index => $value) {
            // Additional check
            if (!empty($value)) {
                // Ensure we have only clean values
                if (strpos(self::SEPARATOR, $value) === false) {
                    array_push($target, $value);
                }
            }
        }

        // Override with modified one
        $this->collection = $target;
    }
1232448
public function parse($string)
    {
        $hashModes = [];

        foreach($this->hashLibrary as $hash){
            if(preg_match('/'.$hash['regex'].'/i', $string)) {
                foreach($hash['modes'] as $mode) {
                    $hashModes[] = new HashMode([
                        'name' => $mode['name'],
                        'hashcat' => $mode['hashcat'],
                        'john' => $mode['john'],
                        'extended' => $mode['extended'],
                    ]);
                }
            }
        }

        $this->modes = $hashModes;
        return $this;
    }
358854
public function splitString($string)
    {
        if ($this->digits->hasStringConflict()) {
            throw new \RuntimeException('The number base does not support string presentation');
        }

        $pattern = $this->getDigitPattern();

        if ((string) $string === '') {
            $digits = [];
        } elseif (is_int($pattern)) {
            $digits = str_split($string, $this->digitPattern);
        } else {
            preg_match_all($pattern, $string, $match);
            $digits = $match[0];
        }

        return $this->canonizeDigits($digits);
    }
1261847
public static function jsonToArray($json)
    {
        if (empty($json)) {
            return null;
        }

        $array = json_decode($json, true);

        switch (json_last_error()) {
            case JSON_ERROR_NONE:
                $message = null;
                break;

            case JSON_ERROR_STATE_MISMATCH:
                $message = 'Invalid or malformed JSON';
                break;

            case JSON_ERROR_UTF8:
                $message = 'Malformed UTF-8 characters, possibly incorrectly encoded';
                break;

            case JSON_ERROR_DEPTH:
                $message = 'The maximum stack depth has been exceeded';
                break;

            case JSON_ERROR_CTRL_CHAR:
                $message = 'Control character error, possibly incorrectly encoded';
                break;

            case JSON_ERROR_SYNTAX:
                $message = 'Syntax error, malformed JSON';
                break;

            default:
                $message = 'Unknown error';
                break;
        }

        if (!empty($message)) {
            throw new \InvalidArgumentException('JSON Error: ' . $message);
        }

        return $array;
    }
1164094
protected function parseString($string) {
        $matches = [];

        if (preg_match_all($this->regex, $string, $result) !== false) {
            $matches = $result[0];
        }

        return $matches;
    }
654971
public function decode($string)
    {
        if ($this->isSerialized($string)) {
            return $this->unserialize($string);
        }

        $result = json_decode($string, true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \InvalidArgumentException('Unable to unserialize value.');
        }

        return $result;
    }
240982
public function decode(string $data): array
    {
        $document = new \DOMDocument();

        if (!@$document->loadXML($data)) {
            throw DeserializerRuntimeException::createNotParsable($this->getContentType());
        }

        return $this->transformType($document->getElementsByTagName('object')->item(0));
    }
600740
private function parseJsonFile(string $file): array
    {
        if (!is_file($file)) {
            throw new \InvalidArgumentException("$file is not a file");
        }

        $json = json_decode(file_get_contents($file), true);

        if (null === $json) {
            throw new \RuntimeException("File $file cannot be decoded");
        }

        return $json;
    }