Question

I know there are many questions here about the unexpected token in JSON error but nothing seems to apply in my case.
In my case I log into the admin backend and get this error:
error message
I managed to find the part which causes the error in the source code (Source page in browser):

<!--
/**
 * Copyright &copy; Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<div class="admin__data-grid-outer-wrap" data-bind="scope: 'notification_area.notification_area'">
    <div data-role="spinner" data-component="notification_area.notification_area.columns"
         class="admin__data-grid-loading-mask">
        <div class="spinner">
            <span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span>
        </div>
    </div>
    <!-- ko template: getTemplate() --><!-- /ko -->
    <script type="text/x-magento-init">{"*": {"Magento_Ui/js/core/app": }}</script>
</div>

I as well managed to figure out that it is inside the notifications container but I do not know which block causes the error. And I don't know which template is responsible for the code.

Anyone knows which block generates this code or which template contains it?

I already did the following:

  • cleared cache
  • removed static content
  • static content deploy
  • removed vendor and did a composer install
  • removed generated code

Any help is very appreciated.

Was it helpful?

Solution

\Magento\Ui\TemplateEngine\Xhtml\Result::appendLayoutConfiguration calls \Magento\Framework\View\Layout\Generator\Structure::generate and that produces wrong invalid json.

json_last_error_msg() gives following message:

Malformed UTF-8 characters, possibly incorrectly encoded

Debugging further and into \Magento\Ui\TemplateEngine\Xhtml\Result::appendLayoutConfiguration showed wrong encoded characters:
wrong encoding

There is no check if if the json is valid. In 2.3 it would throw an error.

Removing the wrong notification from admin_system_messages fixed it.

OTHER TIPS

You need to pass at least empty value for "Magento_Ui/js/core/app" either change the content or remove following line.<script type="text/x-magento-init">{"*": {"Magento_Ui/js/core/app": }}</script> finally output will be <script type="text/x-magento-init">{"*": {"Magento_Ui/js/core/app":"" }}</script>

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top