---
title: "Error Solved: Unable To Serialize Value in Magento 2"
url: "https://magecomp.com/blog/solved-unable-to-serialize-value-in-magento-2/"
date: "2022-03-09T10:00:16+00:00"
modified: "2022-03-09T10:00:16+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "Magento Tutorials"
word_count: 599
reading_time: "3 min read"
summary: "Hello Magento Friends,"
description: "Get rid of Unable to serialize value error on the checkout page after Upgrading to Magento 2.4.x. Find more"
keywords: "Magento Tutorials"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Configure Shipment Comments in Magento 2? &#8211; Episode 2"
    url: "https://magecomp.com/blog/configure-shipment-comments-magento-2/"
  - title: "How to View the Import History in Magento 2"
    url: "https://magecomp.com/blog/view-import-history-magento-2/"
  - title: "How to Setup Cron Job Magento 2: Magento 2.4 updated"
    url: "https://magecomp.com/blog/setup-cron-job-magento-2-4/"
---

# Error Solved: Unable To Serialize Value in Magento 2

_Published: March 9, 2022_  
_Author: Dhiren Vasoya_  

![Error Solved Unable To Serialize Value in Magento 2](https://magecomp.com/blog/wp-content/uploads/2022/03/Error-Solved-Unable-To-Serialize-Value-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

How are you all doing? I am here with this tutorial to solve the issue of unable to serialize value in Magento 2.
While upgrading the Magento 2 version, sometimes you may face the unable to serialize value error on the checkout page.
**“report.CRITICAL: Unable to serialize value. Error: Malformed UTF-8 characters, possible incorrectly encoded.“**

Upgrade your Magento store error-free with the [**Best Magento Upgrade service**](https://magecomp.com/magento-upgrade-service.html)

For now, let’s move on to solve the unable to serialize value error in Magento 2.
## How to Solve Unable To Serialize Value Error in Magento 2?
**Step 1:** Create **registration.php** at the given below path
**app\code\Vendor\Extension\registration.php**

Now, add the code as follows
```
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Vendor_Extension',
__DIR__
);
```

**Step 2:** Create **module.xml** at the below path
**app\code\Vendor\Extension\etc\module.xml**

Then add the code as mentioned below
```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Extension" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Framework" />
        </sequence>
    </module>
</config>
```

**Step 3:** Create **di.xml** at the following path
**app\code\Vendor\Extension\etc\di.xml**

Then append the code as given below
```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
     <preference for="MagentoFrameworkSerializeSerializerJson" type="VendorExtensionRewriteMagentoFrameworkSerializeSerializerJson" />
     <preference for="MagentoFrameworkSerializeSerializerJsonHexTag" type="VendorExtensionRewriteMagentoFrameworkSerializeSerializerJsonHexTag" />
</config>
```

**Step 4:** Now, create **Json.php** at the path mentioned below
**app\code\Vendor\Extension\Rewrite\Magento\Framework\Serialize\Serializer\Json.php**

And include the code in it as given below
```
<?php

namespace VendorExtensionRewriteMagentoFrameworkSerializeSerializer;

class Json extends MagentoFrameworkSerializeSerializerJson
{
    public function utf8ize($mixed)
    {
        if (is_array($mixed))
        {
            foreach ($mixed as $key => $value)
            {
                $mixed[$key] = $this->utf8ize($value);
            }
        } elseif (is_string($mixed))
          {
              return mb_convert_encoding($mixed, "UTF-8", "UTF-8");
          }
        return $mixed;
    }

/**
* @inheritDoc
* @since 101.0.0
*/

    public function serialize($data)
    {
        $result = json_encode($this->utf8ize($data));
        if (false === $result)
        {
            throw new InvalidArgumentException("Unable to serialize value. Error: " . json_last_error_msg());
        }
        return $result;
    }

/**
* @inheritDoc
* @since 101.0.0
*/

    public function unserialize($string)
    {
        $result = json_decode($string, true);
        if (json_last_error() !== JSON_ERROR_NONE)
        {
            throw new InvalidArgumentException("Unable to unserialize value. Error: " . json_last_error_msg());
        }
        return $result;
    }
}
```

**Step 5:** Now, create **JsonHexTag.php** at the following path
**app\code\Vendor\Extension\Rewrite\Magento\Framework\Serialize\Serializer\JsonHexTag.php**

Then write the code as below
```
<?php

namespace VendorExtensionRewriteMagentoFrameworkSerializeSerializer;

class JsonHexTag extends MagentoFrameworkSerializeSerializerJsonHexTag
{
    /**
    * @inheritDoc
    * @since 102.0.1
    */

    public function serialize($data): string
    {
        $data = $this->utf8convert($data);
        $result = json_encode($data, JSON_HEX_TAG);
        if (false === $result)
        {
            throw new InvalidArgumentException('Unable to serialize value.');
        }
        return $result;
    }
    public function utf8convert($mixed, $key = null)
    {
        if (is_array($mixed))
        {
            foreach ($mixed as $key => $value)
            {
                $mixed[$key] = $this->utf8convert($value, $key);
            }
        } elseif (is_string($mixed))
          {
              $fixed = mb_convert_encoding($mixed, "UTF-8", "UTF-8");
              return $fixed;
          }
        return $mixed;
    }
}
```

## Conclusion:
This way you can easily get rid of the serialize value error in Magento 2. If you have any doubts about the above steps, contact me via the comment section. Share the solution with your other developer friends to help them get out of the unable to serialize error.
**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/solved-unable-to-serialize-value-in-magento-2/](https://magecomp.com/blog/solved-unable-to-serialize-value-in-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-10-08 08:07:51 UTC_  
