"An error occurred" / "Bad JSON escape sequence" in Sitecore 8.x Experience Editor Error


Note: This issue appears to have been resolved by Sitecore as of 8.1 Update-2 (rev. 160302).

There is a known issue in Sitecore 8 (as of Update-6) and Sitecore 8.1 (initial release) that causes errors when attempting to edit the Active Commerce Checkout page using the Experience Editor. This also affects the Sherpa demo site home page. Making changes and clicking save will result in an error on the page:

and an error in the log:

54740 09:13:53 ERROR Bad JSON escape sequence: \a. Path 'r.d.r[22].rls.ruleset.rule[0].conditions.condition.@value', line 156, position 44.

This has to do with using rules which contain a "\" character in a condition's value.

Here is the workaround from Sitecore:

1. Open the \Website\sitecore\shell\client\Sitecore\ExperienceEditor\Commands\Save.js file.
2. Replace the following line in the execute: function (context) function:
        context.currentContext.scLayout = Sitecore.ExperienceEditor.Web.encodeHtml(window.parent.document.getElementById("scLayout").value);
     with this line:
        context.currentContext.scLayout = Sitecore.ExperienceEditor.Web.encodeHtml(window.parent.document.getElementById("scLayout").value.replace(/\\/g, '\\\\'));
    For 8.1, the fix is slightly different, replacing:
        context.currentContext.scLayout = ExperienceEditor.Web.encodeHtml(window.parent.document.getElementById("scLayout").value);
     with this line:
        context.currentContext.scLayout = ExperienceEditor.Web.encodeHtml(window.parent.document.getElementById("scLayout").value.replace(/\\/g, '\\\\'));
3. Save these changes and close the file.
4. Clear your browser cache.
To track the future status of this Sitecore bug, please use the reference number 55394. More information about Sitecore public reference numbers can be found here.
Have more questions? Submit a request