Codifica el parámetro a JSON.
@param mixed $value
@return string
963167
public function encode($value)
    {
        $json = json_encode($value);

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

        return $json;
    }
262761
public function sanitize($value)
    {
        if(!$value instanceof KObjectConfigJson)
        {
            if(is_string($value)) {
                $value = $this->getObject('object.config.factory')->fromString('json', $value);
            } else {
                $value = $this->getObject('object.config.factory')->createFormat('json', $value);
            }
        }

        return $value;
    }
1128373
public static function stringify($value)
    {
        $string = '';
        if (is_scalar($value)) {
            // integer, float, string, boolean
            $string = (string)$value;
        } elseif (is_resource($value)) {
            // resource
            $string = '[resource]';
        } else {
            // array, object, null, callable
            $string = json_encode($value);
        }
        return $string;
    }
1143349
public static function stringify($value)
    {
        if (is_string($value)) {
            return $value;
        }
        if ($value === null || is_bool($value)) {
            return var_export($value, true);
        }

        if (is_array($value) || (is_object($value) && !method_exists($value, '__toString'))) {
            return json_encode($value, JSON_ERROR_NONE | JSON_UNESCAPED_SLASHES);
        }
        return (string)$value;
    }
1300522
public function checkJson($value)
    {
        if (!Type::isStringLike($value)) {
            return false;
        }

        json_decode($value);

        return json_last_error() === JSON_ERROR_NONE;
    }
1282151
public function getValueAttribute($value) {
        if ($this->isJson($value)) {
            return json_decode($value);
        }
        if ($this->isSerialized($value)) {
            return unserialize($value);
        }
        return $value;
    }
729081
private function formatValueForApi($value)
    {
        $type = gettype($value);

        switch ($type) {
            case 'string':
                return ['string_value' => $value];
            case 'double':
            case 'integer':
                return ['number_value' => $value];
            case 'boolean':
                return ['bool_value' => $value];
            case 'NULL':
                return ['null_value' => NullValue::NULL_VALUE];
            case 'array':
                if (!empty($value) && $this->isAssoc($value)) {
                    return ['struct_value' => $this->formatStructForApi($value)];
                }

                return ['list_value' => $this->formatListForApi($value)];
        }
    }
503237
protected function encode($value)
    {
        if (is_object($value) && method_exists($value, 'getJs')) {
            return new JsExpression($value->getJs());
        } elseif (is_bool($value)) {
            return new JsExpression(($value ? 'true' : 'false'));
        } elseif (is_array($value)) {
            $parsed = [];
            foreach ($value as $child) {
                $parsed[] = $this->encode($child);
            }
            return $parsed;
        }
        try {
            // a value may contain a valid JSON string
            return Json::decode($value);
        } catch (InvalidParamException $e) {
        }
        return $value;
    }
575733
protected function parseStringsToNativeTypes($value)
    {
        if (is_array($value)) {
            return array_map([$this, 'parseStringsToNativeTypes'], $value);
        }

        if (! is_string($value)) {
            return $value;
        }

        $parsedValue = json_decode($value, true);

        if (json_last_error() === JSON_ERROR_NONE) {
            return $parsedValue;
        }

        return $value;
    }
464305
public static function encode($value)
    {
        $encoded = json_encode($value, JSON_UNESCAPED_UNICODE);

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new \InvalidArgumentException(sprintf(
                'Could not encode value into json. Error %s and message %s',
                json_last_error(),
                json_last_error_msg()
            ));
        }

        return $encoded;
    }
942889
static function toJSON($value, $format = true)
    {
        if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
            $f = JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE;
            if ($format) $f = $f|JSON_PRETTY_PRINT;
            return json_encode($value, $f);
        }else{
            return F::special_unicode_to_utf8(json_encode($value));
        }
    }
586866
protected function output($value)
    {
        if ($value instanceof Renderable) {
            $value = $value->render();
        }

        if ($value instanceof Htmlable) {
            $value = $value->toHtml();
        }

        if ($value instanceof Jsonable) {
            $value = $value->toJson();
        }

        if (!is_null($value) && !is_scalar($value)) {
            return sprintf('<pre>%s</pre>', var_export($value, true));
        }

        return $value;
    }
353889
protected static function stringify($value): string
    {
        if (is_object($value)) {
            return 'Object(' . get_class($value) . ')';

        } elseif (is_array($value)) {
            $strings = [];
            foreach ($value as $k => $v) {
                $strings[] = sprintf('%s => %s', $k, self::stringify($v));
            }
            return 'Array(' . implode(', ', $strings) . ')';

        } elseif (is_resource($value)) {
            return 'Resource (' . get_resource_type($value) . ')';

        } elseif (is_null($value)) {
            return 'null';

        } elseif (is_bool($value)) {
            return $value ? 'true' : 'false';
        }

        return "'" . (string)$value . "'";
    }
381568
private function getSourceValue($value)
    {
        if (!empty($value)) {
            $value = json_decode($value, true);

            if (preg_match('/^image\//i', $value[0]['type']))
                return str_replace('\\', '/', $value[0]['url']);

            return "";
        }

        return "";
    }
206628
protected function formatValue($value)
    {
        if (PHP_VERSION_ID < 50400) {
            return str_replace('\/', '/', json_encode($value));
        }

        return json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    }
120865
protected function serializeValue($value)
    {
        if (is_string($value)) {
            return $value;
        }
        if (is_object($value) || is_array($value)) {
            return json_encode($value);
        }
    }
1248942
protected function wrapValue($value)
    {
        if ($value === '*') {
            return $value;
        }

        // If querying hstore
        if (preg_match('/\[(.*?)\]/', $value, $match)) {
            return (string)str_replace(array('[', ']'), '', $match[1]);
        }

        // If querying json column
        foreach ($this->jsonOperators as $operator) {
            if (stripos($value, $operator)) {
                list($value, $key) = explode($operator, $value, 2);
                return parent::wrapValue($value) . $operator . $key;
            }
        }

        return parent::wrapValue($value);
    }