Return the data as a well-formatted string.
Any scalar value will be casted to an array
@param int $option \json_encode() options
@param int $depth \json_encode() depth
@return string
485357
public function getDataAsJsonString($option = 0, $depth = 512): string
    {
        $data = $this->get();

        if (\is_object($data) || \is_array($data)) {
            $data = \json_encode($data, $option, $depth);
        } else {
            $data = \json_encode([$data], $option, $depth);
        }

        return \json_encode($data, $option, $depth);
    }
624425
protected function getOptionsString()
    {
        $value   = $this->getValue();
        $options = '';
        if ($this->get('_first_option')) {
            $options .= sprintf('<option value="">%s</option>', $this->get('_first_option'));
        }
        $optionsList = $this->get('_options') ?: array();
        foreach ($optionsList as $k => $v) {
            $selected = '';
            // be flexible, accept a non-array value
            if ((is_string($value) && $k == $value) || (is_array($value) && in_array($k, $value))) {
                $selected = 'selected="selected"';
            }
            $options .= sprintf('<option value="%s" %s>%s</option>', htmlentities($k, ENT_COMPAT), $selected, $v);
        }

        return $options;
    }
845604
public function jsonDecode($string, $assoc = false, $depth = 512, $options = 0)
    {
        return json_decode($string, $assoc, $depth, $options);
    }
98897
static function formatOptions( $options, $default = false ) {
		$data = '';

		foreach( $options as $label => $value ){
			if( is_array( $value ) ) {
				$contents = self::formatOptions( $value, $default );
				$data .= self::tags( 'optgroup', array( 'label' => $label ), $contents ) . "\n";
			} else {
				$data .= self::option( $label, $value, $value === $default ) . "\n";
			}
		}

		return $data;
	}
1154392
public static function deserialise(
			$str,
			$assoc = false,
			$depth = self::DEFAULT_INPUT_DEPTH,
			$options = 0){
		
		$o = \json_decode($str, $assoc, $depth, $options);
		static::$_LastError = \json_last_error();
		return $o;
		
	}
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()];
    }
1362114
public function encode(array $options = [])
    {
        $options = array_replace(
            [
                'encodingOptions'       => $this->getOption('encodingOptions')
            ],
            $options
        );

        $json = json_encode($this->getContents(), $options['encodingOptions']);

        if ($json === false) {
            switch (json_last_error()) {
                case JSON_ERROR_DEPTH:
                    $msg = 'The maximum stack depth has been exceeded.';

                    break;
                case JSON_ERROR_STATE_MISMATCH:
                    $msg = 'Occurs with underflow or with the modes mismatch.';

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

                    break;
                case JSON_ERROR_UTF8:
                    $msg = 'alformed UTF-8 characters, possibly incorrectly encoded.';

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

            throw EncodeException::create($this->getPath(), $msg);
        }

        return $json;
    }
128636
public function canonical($option)
	{
		if (is_array($option))
		{
			$option = implode('', $option);
		}
		$option = preg_replace('/[^A-Z0-9_\.-]/i', '', $option);
		if (substr($option, 0, strlen('com_')) != 'com_')
		{
			$option = 'com_' . $option;
		}
		return $option;
	}
829248
public function renderContent()
    {
        $string = json_encode($this->getContent(), $this->option, $this->depth);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \RuntimeException('Json encode error ! (error: ' . json_last_error_msg() . ')');
        }

        return $string;
    }
533517
public static function encode($value, $options = 0)
    {
        $json = json_encode($value, $options);

        $error = self::getLastError();
        if ($json === null || !empty($error)) {
            $GLOBALS['log']->error('Json::encode():' . $error . ' - ' . print_r($value, true));
        }

        return $json;
    }
82388
public static function encode($value, $options = null)
    {
        if ($options === null) {
            $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT;
        }

        $json = json_encode($value, $options);

        static::handleJsonError(json_last_error());

        return $json;
    }
690410
public static function encode($array, $options = null)
    {
        $result = false;
        $highPrecisionFloatMap = static::getHighPrecisionFloatMap($array);

        if (version_compare(PHP_VERSION, '5.4', '>=')) {
            $jsonOptions = JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES;
            if (!empty($options)) {
                foreach ($options as $o) {
                    $jsonOptions += $o;
                }
            }
            $result = json_encode($array, (int)$jsonOptions);
        } else {
            $result = json_encode($array);

            // Unicode fix: http://stackoverflow.com/a/2934602
            $result = preg_replace_callback(
                '/\\\\u([0-9a-f]{4})/i',
                function ($match) {
                    return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
                },
                $result
            );
            // Escaped slashes fix
            $result = str_replace('\/', '/', $result);
        }

        foreach($highPrecisionFloatMap as $scientificValueString => $floatValueString) {
            // Replace all scientific values by equivalent floatValues
            $result = str_ireplace($scientificValueString, $floatValueString, $result);
        }
        return $result;
    }
1015623
private function encodeCheckVersion($dataValid, $optionsValid, $depthValid)
    {
        //In 5.4 add depth param
        if(version_compare(PHP_VERSION, '5.4.0') >= 0)
        {
            return json_encode($dataValid, $optionsValid, $depthValid);
        }

        return json_encode($dataValid, $optionsValid);
    }
1027637
public function toJson($options = 0)
	{
		$json = json_encode($this->jsonSerialize(), $options);

		if (JSON_ERROR_NONE !== json_last_error()) {
			throw JsonEncodingException::forObject($this, json_last_error_msg());
		}

		return $json;
	}
161249
public function toJson(int $options = 0, int $depth = 512): string
    {
        /** @noinspection PhpComposerExtensionStubsInspection */
        $return = \json_encode($this->getArray(), $options, $depth);
        if ($return === false) {
            return '';
        }

        return $return;
    }
972445
public static function jsonEncode($value): string
	{
		return Nette\Utils\Json::encode($value, self::jsonEncodeOptions());
	}
244578
private function jsEncode($val)
	{
		if (is_null($val)) {
			return 'null';
		}
		if ($val === false) {
			return 'false';
		}
		if ($val === true) {
			return 'true';
		}
		if (is_scalar($val))
		{
			if (is_float($val))
			{
				// Always use "." for floats.
				$val = str_replace(",", ".", strval($val));
			}

			// Use @@ to not use quotes when outputting string value
			if (strpos($val, '@@') === 0) {
				return substr($val, 2);
			}
			else {
				// All scalars are converted to strings to avoid indeterminism.
				// PHP's "1" and 1 are equal for all PHP operators, but
				// JS's "1" and 1 are not. So if we pass "1" or 1 from the PHP backend,
				// we should get the same result in the JS frontend (string).
				// Character replacements for JSON.
				static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'),
				array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));

				$val = str_replace($jsonReplaces[0], $jsonReplaces[1], $val);
				if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.') {
					return $val;
				}

				return '"' . $val . '"';
			}
		}
		$isList = true;
		for ($i = 0, reset($val); $i < count($val); $i++, next($val))
		{
			if (key($val) !== $i)
			{
				$isList = false;
				break;
			}
		}
		$result = array();
		if ($isList)
		{
			foreach ($val as $v) $result[] = $this->jsEncode($v);
			return '[ ' . join(', ', $result) . ' ]';
		}
		else
		{
			foreach ($val as $k => $v) $result[] = $this->jsEncode($k).': '.$this->jsEncode($v);
			return '{ ' . join(', ', $result) . ' }';
		}
	}