Magento 2: How to find which config causing error "Malformed UTF-8 characters, possibly incorrectly encoded" when trying to serialize checkout config

Magento 2: How to find which config causing error "Malformed UTF-8 characters, possibly incorrectly encoded" when trying to serialize checkout config

July 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2: How to find which config causing error "Malformed UTF-8 characters, possibly incorrectly encoded" when trying to serialize checkout config

Magento 2: Debugging UTF-8 Serialization Errors in Checkout Config

When working with Magento 2, you might encounter errors when trying to serialize checkout configuration data. This can result in exceptions like “Malformed UTF-8 characters, possibly incorrectly encoded.” In this post, we’ll guide you through identifying the problematic config value causing this issue.

Tracing the Serialization Error in Checkout Config

Let’s start by tracing the error back to its source:

  1. The exception is thrown during the rendering of vendor/magento/module-checkout/view/frontend/templates/onepage.phtml. This file includes a line that serializes and outputs the checkout configuration:
        window.checkoutConfig = <?php /* @noEscape */ $block->getSerializedCheckoutConfig() ?>;
  1. The getSerializedCheckoutConfig() method is defined in vendor/magento/module-checkout/Block/Onepage.php. This method retrieves the checkout config data and passes it to the serialize function.

  2. The actual serialization happens using Magento’s built-in serializer, which uses the JsonHexTag strategy located at vendor/magento/framework/Serialize/Serializer/JsonHexTag.php.

Enhancing Error Messaging for Diagnosis

To make debugging easier, you can enhance the exception message by adding the json_last_error_msg() function to provide more context about the serialization error:

    public function getSerializedCheckoutConfig()
    {
        try {
            return json_encode($this->getSortedCheckoutConfig(), JSON_THROW_ON_ERROR);
        } catch (JsonException $e) {
            throw new InvalidArgumentException(
                'Unable to serialize value. Error: ' . $e->getMessage(),
                $e
            );
        }
    }

After this modification, the error message will include details like “Malformed UTF-8 characters, possibly incorrectly encoded.”

Identifying the Problematic Config Value

To find out which specific checkout configuration value is causing the issue, you’ll need to dive into the data structure being serialized. Here’s a step-by-step approach:

1. Inspect the Checkout Config Data Structure

The checkout_config database table in your Magento installation stores the configuration values used during onepage checkout.

SELECT *
FROM checkout_config;

You’ll find a JSON column (value) containing the configuration data as an associative array.

2. Locate the Malformed UTF-8 Characters

The serialization error typically occurs due to non-breaking spaces or other special characters that are not encoded properly in your config values.

To quickly identify problematic entries:

  1. Export the checkout_config table as a JSON file.
  2. Open the exported JSON file and search for any characters that don’t appear correctly (e.g., strange symbols, squares, or question marks).

3. Correlate with Magento Configuration

Match the problematic JSON key(s) you found in step 2 with the actual Magento configuration settings they represent. You can use tools like Magento’s Configuration Management to cross-reference and locate the corresponding admin panel entries.

Quick Fix for Malformed UTF-8 Characters

Once you’ve identified the problematic config key(s) with malformed UTF-8 characters:

  1. Manually edit the value column in the checkout_config table, replacing any incorrectly encoded special characters.
  2. Make sure to use proper JSON syntax and encoding when updating the values.

For example, if a non-breaking space character is causing issues, replace it with its HTML entity or a properly encoded UTF-8 representation:

"key": "Some value with ÿor correctly encoded characters",

Conclusion

Debugging serialization errors in Magento checkout configuration can be challenging due to the complex data structure involved. However, by following the steps outlined above—enhancing error messages, inspecting database content, and cross-referencing with Magento config settings—you should be able to quickly locate and fix any malformed UTF-8 characters causing issues during checkout.

If you need further assistance or want to explore more advanced debugging techniques for Magento 2, feel free to reach out to us at Laravel Company. Our team of experienced developers specializes in providing tailored solutions for Magento e-commerce platforms.

Magento 2 Checkout Extensions Themes

Our network