cancel
Showing results for 
Search instead for 
Did you mean: 

{"0":"Unable to unserialize value. Error: Syntax error","1":"#1

Highlighted

{"0":"Unable to unserialize value. Error: Syntax error","1":"#1

Hello, I'm new here and I'm trying to learn to understand error log message and how to solve it. 

I have already cleared Caché, because that sometimes helps me. 

 

I really will appreciate your help. 

 

Message error: 

{"0":"Unable to unserialize value. Error: Syntax error","1":"#1 Magento\\Framework\\App\\PageCache\\Kernel->load() called at [vendor\/magento\/module-page-cache\/Model\/App\/FrontController\/BuiltinPlugin.php:71]\n#2 Magento\\PageCache\\Model\\App\\FrontController\\BuiltinPlugin->aroundDispatch(&Magento\\Framework\\App\\FrontController\\Interceptor#00000000263cc0b2000000007b567278#, &Closure#00000000263cc0af000000007b567278#, &Magento\\Framework\\App\\Request\\Http#00000000263cc1c6000000007b567278#) called at [vendor\/magento\/framework\/Interception\/Interceptor.php:135]\n#3 Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}(&Magento\\Framework\\App\\Request\\Http#00000000263cc1c6000000007b567278#) called at [vendor\/magento\/framework\/Interception\/Interceptor.php:153]\n#4 Magento\\Framework\\App\\FrontController\\Interceptor->___callPlugins('dispatch', array(&Magento\\Framework\\App\\Request\\Http#00000000263cc1c6000000007b567278#), array(array('page_cache_from_...', 'Amasty_Shopby::P...', 'Amasty_ShopbySeo...', 'storeCookieValid...', 'install', 'configHash'), array('front-controller...', 'Amasty_ShopbySeo...'), 'requestPreproces...')) called at [generated\/code\/Magento\/Framework\/App\/FrontController\/Interceptor.php:26]\n#5 Magento\\Framework\\App\\FrontController\\Interceptor->dispatch(&Magento\\Framework\\App\\Request\\Http#00000000263cc1c6000000007b567278#) called at [vendor\/magento\/framework\/App\/Http.php:116]\n#6 Magento\\Framework\\App\\Http->launch() called at [generated\/code\/Magento\/Framework\/App\/Http\/Interceptor.php:24]\n#7 Magento\\Framework\\App\\Http\\Interceptor->launch() called at [vendor\/magento\/framework\/App\/Bootstrap.php:261]\n#8 Magento\\Framework\\App\\Bootstrap->run(&Magento\\Framework\\App\\Http\\Interceptor#00000000263cc120000000007b567278#) called at [index.php:39]\n","url":"\/","script_name":"\/index.php","report_id":"26f4e90059df0e55dc9b975f38e839f815746c021b4a30ce96de6c34488658c0"}
1 REPLY 1
Highlighted

Re: {"0":"Unable to unserialize value. Error: Syntax error","1":"

@danielacam74fb 

 

The problem is in /vendor/magento/framework/Serialize/Serializer/Json.php there is a function unserialize($string) which gives you a syntax error if string is serialized (not json but php serialization).

There is a workaround - you can check if string is serialized (vs json-encoded) and then use serialize($string). Change unserialize to:

public function unserialize($string)
{
    if($this->is_serialized($string))
    {
        $string = $this->serialize($string);
    }
    $result = json_decode($string, true);
    if (json_last_error() !== JSON_ERROR_NONE) {
         throw new \InvalidArgumentException('Unable to unserialize value.');

    }
    return $result;
}

and add function to check if string is serialized:

function is_serialized($value, &$result = null)
{
    // Bit of a give away this one
    if (!is_string($value))
    {
        return false;
    }
    // Serialized false, return true. unserialize() returns false on an
    // invalid string or it could return false if the string is serialized
    // false, eliminate that possibility.
    if ($value === 'b:0;')
    {
        $result = false;
        return true;
    }
    $length = strlen($value);
    $end    = '';
    switch ($value[0])
    {
        case 's':
            if ($value[$length - 2] !== '"')
            {
                return false;
            }
        case 'b':
        case 'i':
        case 'd':
            // This looks odd but it is quicker than isset()ing
            $end .= ';';
        case 'a':
        case 'O':
            $end .= '}';
            if ($value[1] !== ':')
            {
                return false;
            }
            switch ($value[2])
            {
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                    break;
                default:
                    return false;
            }
        case 'N':
            $end .= ';';
            if ($value[$length - 1] !== $end[0])
            {
                return false;
            }
            break;
        default:
            return false;
    }
    if (($result = @unserialize($value)) === false)
    {
        $result = null;
        return false;
    }
    return true;
}

You can restore class to default and there wont be such problem in future.

Manish Mittal
https://www.manishmittal.com/