Convert between JSON and array types.

@param string $value
@param array $options
@param int $mode
@return string
503250
public function json($value, array $options, $mode) {
        if ($mode === self::TO && $options['encode']) {
            return json_encode($value);
        }

        if ($mode === self::FROM && $options['decode']) {
            return json_decode($value, !$options['object']);
        }

        return $value;
    }
1217773
public static function json(&$value, $options = ['json_assoc'=>true, 'json_schema'=>[], 'default'=>null])
    {
        $json_assoc = isset($options['json_assoc']) && $options['json_assoc'] ? true : false;
        $value = @json_decode(trim($value), $json_assoc);

        if ($value !== null && $json_assoc && isset($options['json_schema']) && $options['json_schema'] && is_array($options['json_schema'])) {
            foreach ($options['json_schema'] as $field => $opt_arr) {
                self::validate(
                    $value[$field],
                    isset($opt_arr[0]) ? $opt_arr[0] : self::NONE_TYPE,
                    isset($opt_arr[1]) && is_array($opt_arr[1]) ? $opt_arr[1] : []
                );
            }
        } elseif ($value === null) {
            $value = isset($options['default']) ? $options['default'] : null;
        }

        return $value;
    }
208062
public static function reset($value, array $options = [])
    {
        self::exclure($options, ['type', 'value']);

        return self::input('reset', 'null', $value, $options);
    }
345275
public function filter($value, array $options = [])
    {
        if ( ! is_string($value) || empty(trim($value)))
            return $value;

        $this->checkOptions($options);

        list($currentFormat, $targetFormat) = array_map('trim', $options);

        return DateTime::createFromFormat($currentFormat, $value)->format($targetFormat);
    }
913924
public static function html($value, array $options = array()) {
        $options = $options + array(
            'strip' => true,
            'whitelist' => ''
        );

        if ($options['strip']) {
            $value = strip_tags($value, $options['whitelist']);
        }

        return static::escape($value, $options);
    }
1023578
private static function getChoices(Options $options, $value)
    {
        return $value instanceof ChoiceLoaderInterface && empty($options['choices'])
            ? $value->loadChoiceList()->getStructuredValues()
            : $options['choices'];
    }
540657
public function sanitize($value, $mode = null)
    {
        if ($mode === null) {
            $mode = $this->sanitize;
        }
        if (is_array($value)) {
            $hash = md5(json_encode($value));
            /* Optimize lazy loading */
            if (isset(static::$_sanitizeCache[$hash])) {
                return static::$_sanitizeCache[$hash];
            }

            return static::$_sanitizeCache[$hash] =
                ArrayHelper::map(
                    $value,
                    function ($value) use ($mode) {
                        return $this->sanitizeValue($value, $mode);
                    },
                    true
                );
        }

        return $this->sanitizeValue($value, $mode);
    }
746108
private static function toJson(&$var, array $options, int $level = 0)
    {
        if (\is_bool($var) || null === $var || \is_int($var)) {
            return $var;

        }

        if (\is_float($var)) {
            return \is_finite($var)
                ? (\strpos($tmp = \json_encode($var), '.') ? $var : ['number' => "$tmp.0"])
                : ['type' => (string) $var];

        }

        if (\is_string($var)) {
            return self::encodeString($var, $options[self::TRUNCATE]);
        }

        if (\is_array($var)) {
            static $marker;
            if ($marker === null) {
                $marker = \uniqid("\x00", true);
            }
            if (isset($var[$marker]) || $level >= $options[self::DEPTH]) {
                return [null];
            }
            $res = [];
            $var[$marker] = true;
            foreach ($var as $k => & $v) {
                if ($k !== $marker) {
                    $hide = \is_string($k) && isset($options[self::KEYS_TO_HIDE][\strtolower($k)]);
                    $k = \is_int($k) || \preg_match('#^\w{1,50}\z#', $k) ? $k : '"' . self::encodeString($k,
                            $options[self::TRUNCATE]) . '"';
                    $res[] = [$k, $hide ? self::HIDDEN_VALUE : self::toJson($v, $options, $level + 1)];
                }
            }
            unset($var[$marker]);

            return $res;
        }

        if (\is_object($var)) {
            $obj = &self::$liveStorage[\spl_object_hash($var)];
            if ($obj && $obj['level'] <= $level) {
                return ['object' => $obj['id']];
            }

            $editorInfo = null;
            if ($options[self::LOCATION] & self::LOCATION_CLASS) {
                $rc = $var instanceof \Closure ? new \ReflectionFunction($var) : new \ReflectionClass($var);
                $editor = $rc->getFileName() ? Helpers::editorUri($rc->getFileName(), $rc->getStartLine()) : null;
                $editorInfo = $editor ? [
                    'file' => $rc->getFileName(), 'line' => $rc->getStartLine(), 'url' => $editor,
                ] : null;
            }
            static $counter = 1;
            $obj = $obj ?: [
                'id' => self::$livePrefix . '0' . $counter++, // differentiate from resources
                'name' => Helpers::getClass($var),
                'editor' => $editorInfo,
                'level' => $level,
                'object' => $var,
            ];

            if ($level < $options[self::DEPTH] || !$options[self::DEPTH]) {
                $obj['level'] = $level;
                $obj['items'] = [];

                foreach (self::exportObject($var, $options[self::OBJECT_EXPORTERS],
                    $options[self::DEBUGINFO]) as $k => $v) {
                    $vis = 0;
                    if (isset($k[0]) && $k[0] === "\x00") {
                        $vis = $k[1] === '*' ? 1 : 2;
                        $k = \substr($k, \strrpos($k, "\x00") + 1);
                    }
                    $hide = \is_string($k) && isset($options[self::KEYS_TO_HIDE][\strtolower($k)]);
                    $k = \is_int($k) || \preg_match('#^\w{1,50}\z#', $k) ? $k : '"' . self::encodeString($k,
                            $options[self::TRUNCATE]) . '"';
                    $obj['items'][] = [$k, $hide ? self::HIDDEN_VALUE : self::toJson($v, $options, $level + 1), $vis];
                }
            }

            return ['object' => $obj['id']];
        }

        if (\is_resource($var)) {
            $obj = &self::$liveStorage[(string) $var];
            if (!$obj) {
                $type = \get_resource_type($var);
                $obj = ['id' => self::$livePrefix . (int) $var, 'name' => $type . ' resource'];
                if (isset(self::$resources[$type])) {
                    foreach ((self::$resources[$type])($var) as $k => $v) {
                        $obj['items'][] = [$k, self::toJson($v, $options, $level + 1)];
                    }
                }
            }

            return ['resource' => $obj['id']];
        }

        return ['type' => 'unknown type'];
    }
1322590
public function renderJson($value)
    {
        $options = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP;
        return json_encode($value, $options);
    }
856638
public static function boolean($value, $options = null)
    {
        if (!is_null($options)) {
            $options = explode('|', $options);
        }

        if (sizeof($options) != 2) {
            $options = array('No', 'Yes');
        }

        return $options[!!$value];
    }
792625
public static function json($value)
    {
        if (!is_scalar($value) && !method_exists($value, '__toString')) {
            return false;
        }

        json_decode((string) $value);

        return json_last_error() === JSON_ERROR_NONE;
    }
1296623
public function convertToPHPValueSql($value, AbstractPlatform $platform)
    {
        $opts = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;

        if (is_object($value)) {
            if (method_exists($value, 'toJson')) {
                $value = $value->toJson();
            } elseif (method_exists($value, 'toArray')) {
                $value = json_encode($value->toArray(), $opts);
            } else {
                $value = json_encode($value, $opts);
            }
        }

        return parent::convertToPHPValueSql($value, $platform);
    }
433089
public function encodeJson($value, $options = null, $depth = null)
    {
        return $this->utilEncodingService->encodeJson($value, $options, $depth);
    }
735950
public function encodeJson($value)
    {
        if ($value instanceof Arrayable) {
            return $this->encodeArrayable($value);
        } else if (is_array($value)) {
            return $this->encodeArray($value);
        } else if (is_object($value)) {
            return $this->encodeArray((array) $value);
        } else {
            return $value;
        }
    }
242961
public function serialize($value, array $options=[])
    {

        $serialized = json_encode(
            $value,
            $this->bitmask($options),
            $this->getDepth($options)
        );

        return $serialized;

    }
727590
protected function json( $value )
	{
		if( !is_string( $value ) || '' === $value ){
			return false;
		}
		json_decode( $value );
		return (json_last_error() === JSON_ERROR_NONE);
	}
308275
static public function renderField($value, array $options, $item)
    {
        if (empty($options['name'])) {
            return '';
        }
        if (empty($value) || !is_array($value)) {
            return '';
        }

        if (!$item instanceof EntityInterface) {
            return '';
        }

        $output = field_view_field($item->getEntityTypeId(), $item, $options['name'], self::LIST_VIEW_MODE);

        return drupal_render($output);
    }