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"
        <div class="spinner">
    <!-- ko template: getTemplate() --><!-- /ko -->
    <script type="text/x-magento-init">{"*": {"Magento_Ui/js/core/app": }}</script>

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.

  • Debug entry point: \Magento\Ui\Component\Wrapper\UiComponent::_toHtml – Daniel Mar 22 '19 at 13:21
  • As per logs there is error in scripts.js file at either line number 117 or 87. keep debugger in that lines – Naisa purushotham Mar 22 '19 at 13:31
  • \Magento\Ui\TemplateEngine\Xhtml\Result::appendLayoutConfiguration seems to generated json which cannot be encoded – Daniel Mar 22 '19 at 13:35
  • 1
    in 2.3 this would throw an exception: github.com/magento/magento2/blob/2.3-develop/app/code/Magento/… because JsonSerializer is used – Alex Mar 22 '19 at 13:44

\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.

| improve this answer | |

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>

| improve this answer | |
  • problem is the error comes from core files so I cannot simple remove something – Daniel Mar 22 '19 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.