Decodes a JSON string.

@param string $json
@param int $options
@return mixed
@throws JsonException
546833
public static function decode(string $json, int $options = 0)
	{
		if (!\preg_match('##u', $json)) {
			throw new JsonException('Invalid UTF-8 sequence', 5); // workaround for PHP < 5.3.3 & PECL JSON-C
		}

		$forceArray = (bool) ($options & self::FORCE_ARRAY);

		if (!$forceArray && \preg_match('#(?<=[^\\\\]")\\\\u0000(?:[^"\\\\]|\\\\.)*+"\s*+:#', $json)) { // workaround for json_decode fatal error when object key starts with \u0000

			throw new JsonException(static::$messages[\JSON_ERROR_CTRL_CHAR]);
		}

		$args = [$json, $forceArray, 512];

		if (\PHP_VERSION_ID >= 50400 && !(\defined('JSON_C_VERSION') && \PHP_INT_SIZE > 4)) { // not implemented in PECL JSON-C 1.3.2 for 64bit systems
			$args[] = \JSON_BIGINT_AS_STRING;
		}

		$value = \json_decode(...$args);

		if ($value === null && $json !== '' && \strcasecmp($json, 'null')) { // '' is not clearing json_last_error
			$error = \json_last_error();

			throw new JsonException(static::$messages[$error] ?? 'Unknown error', $error);
		}

		return $value;
	}
1132630
protected function parse_json( $json ) {

		$data = json_decode( $json, true );

		if ( ! is_array( $data ) ) {
			$data = array();
		}

		return $data;
	}
1017383
protected function jsonDecode($json)
    {
        // From firebase/php-jwt
        if (!(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {
            /**
             * In PHP >=5.4.0, json_decode() accepts an options parameter, that allows you
             * to specify that large ints (like Steam Transaction IDs) should be treated as
             * strings, rather than the PHP default behaviour of converting them to floats.
             */
            $obj = json_decode($json, false, 512, JSON_BIGINT_AS_STRING);
        } else {
            // @codeCoverageIgnoreStart
            /**
             * Not all servers will support that, however, so for older versions we must
             * manually detect large ints in the JSON string and quote them (thus converting
             * them to strings) before decoding, hence the preg_replace() call.
             * Currently not sure how to test this so I ignored it for now.
             */
            $maxIntLength = strlen((string) PHP_INT_MAX) - 1;
            $jsonWithoutBigints = preg_replace('/:\s*(-?\d{'.$maxIntLength.',})/', ': "$1"', $json);
            $obj = json_decode($jsonWithoutBigints);
            // @codeCoverageIgnoreEnd
        }

        return $obj;
    }
429355
public static function get_Json( &$json )
    {
        if( $json instanceof Json ) {
            return $json;
        }
        return !is_null($json)
            ? new Json($json)
            : null
            ;
    }
191642
public function decode($json, $toObject = FALSE)
    {
        if (is_file($json)) {
            if (is_readable($json)) {
                $json = file_get_contents($json);
            } else {
                throw new \ErrorException(self::ERROR_CANNOT_READ_FILE);
            }
        }

        $value = json_decode($json, !$toObject);

        if ($code = json_last_error()) $this->throwError($code);

        return $value;
    }
804736
public static function json_encode($value, $options=0, $depth=512) {
		ref\format::json_encode($value, $options, $depth);
		return $value;
	}
990523
public function toJson($options = 0)
    {
        // Models' toJson() calls their toArray() function.  We don't want this to
        // happen twice
        if (!is_a($this, Model::class)) {
            $this->runSerializeTransforms();
        }

        // Continue execution
        return parent::toJson($options);
    }
159083
public function decode(string $json, bool $assoc = null, int $depth = null, int $options = null)
    {
        list($content, $error) = $this->softDecode($json, $assoc, $depth, $options);
        if ($error !== null) {
            throw $error;
        }
        return $content;
    }
1222255
public function toJson($options = 0)
    {
        if ($this->object instanceof Jsonable) {
            return $this->object->toJson();
        }

        return json_encode($this->object);
    }
660120
public function softDecode(string $json, bool $assoc = null, int $depth = null, int $options = null): array
    {
        \assert('($depth === null || $depth >= 0) && ($options === null || $options >= 0)');
        $content = json_decode($json, $assoc ?? $this->assoc, $depth ?? $this->depth, $options ?? $this->options);
        return [$content, $this->getError()];
    }
781873
protected function json_encode_options($options)
    {
        $data = $this->prepare_options($options);

        $json = json_encode($data['options']);

        $json = str_replace($data['toReplace'], $data['original'], $json);

        return $json;
    }
863330
public static function fromJson($json)
    {
        $responseData = json_decode($json, true);

        if ( ! $responseData)
            return new static(false, [ResponseV3::E_INVALID_JSON]);

        return static::fromArray($responseData);
    }
230037
public function fromJson($json) {
    Helpers::checkType('json', 'string', $json);
    $decoded_value = json_decode($json);
    if ($decoded_value === null && ($json !== 'null' || $json !== '')) {
      throw new \Exception('Invalid JSON.');
    }
    return $this->setValue($decoded_value);
  }
232127
public function fromJson(string $json): array
    {
        if (!$this->isEmptyValue($json)) {

            if ($decode = json_decode(trim($json), true) and json_last_error() == JSON_ERROR_NONE)
                $this->result = $decode;
            else
                $this->setError(json_last_error(), json_last_error_msg());
        }

        return $this->result;
    }
12051
public function toJson(int $options = 0)
    {
        $json = json_encode($this->toArray(), $options);
        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new JsonEncodeException(json_last_error_msg());
        }

        return $json;
    }
1097759
public function decode(array $options = [])
    {
        $options = array_merge(
            [
                'exceptionOnInvalidType'        => false,
                'objectSupport'                 => false,
                'objectForMap'                  => false
            ],
            $options
        );

        return SymfonyYaml::parse(
            $this->getContents(),
            $options['exceptionOnInvalidType'],
            $options['objectSupport'],
            $options['objectForMap']
        );
    }
966954
public static function fromJson($json)
    {
        $data = json_decode((string)$json, true);

        if (json_last_error() !== JSON_ERROR_NONE || !is_array($data)) {
            throw new \UnexpectedValueException('Invalid JSON message.');
        }

        return new static($data);
    }