# Update auf 5.7.2 Fehler bei Filterund Uncaught SyntaxError: JSON.parse

**URL:** <https://forum.shopware.com/t/update-auf-5-7-2-fehler-bei-filterund-uncaught-syntaxerror-json-parse/89650>\
**Category:** Allgemein\
**Created:** [9. August 2021 um 07:18 UTC](https://forum.shopware.com/t/update-auf-5-7-2-fehler-bei-filterund-uncaught-syntaxerror-json-parse/89650 "2021-08-09T07:18:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephan\_Grass](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@Stephan\_Grass](https://forum.shopware.com/u/Stephan_Grass)\
**Post date:** [9. August 2021 um 07:18 UTC](https://forum.shopware.com/t/update-auf-5-7-2-fehler-bei-filterund-uncaught-syntaxerror-json-parse/89650/1 "2021-08-09T07:18:35Z")

</div>

Hallo,  
nach dem Update auf 5.7.2 haben wir Probleme mit dem Filter.

Es erschinen Fehler wie  
„Uncaught SyntaxError: JSON.parse: expected ‚,‘ or ‚}‘ after property value in object at line 1 column 83938 of the JSON data“ oder  
„Uncaught SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 2035 of the JSON data“

Wo kann der Fehler leigen?

Danke  
Stephan

---

<div class="post-metadata">

**Author:** ![C\_E](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@C\_E](https://forum.shopware.com/u/C_E)\
**Post date:** [8. September 2021 um 08:08 UTC](https://forum.shopware.com/t/update-auf-5-7-2-fehler-bei-filterund-uncaught-syntaxerror-json-parse/89650/2 "2021-09-08T08:08:12Z")

</div>

Das Problem haben wir nach dem Update von 5.6 auf 5.7 auch. Ursache bei uns sind html-Tags in einem Freitextfeld der Hersteller. Könnte aber vermutlich auch jedes andere Feld betreffen.

Das JavascriptPlugin swListingActions führt folgende Codezeile durch (Methode sendListingRequest, ca. Zeile 1009, [Stelle im git](https://github.com/shopware/shopware/blob/e881054085cd86afc729c85278fdd5a848f30581/themes/Frontend/Responsive/frontend/_public/src/js/jquery.listing-actions.js#L1009))

```auto
facets = $textResponse.find('#facets').html(),

```

und versucht das dann als JSON zu parsen. Das funktionert nicht.  
An der Stelle

```auto
facets = $textResponse.find('#facets').text(),

```

nutzen würde das Problem wohl lösen, da kommt man aber nicht einfach so mal ran.

---

<div class="post-metadata">

**Author:** ![C\_E](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@C\_E](https://forum.shopware.com/u/C_E)\
**Post date:** [8. September 2021 um 08:46 UTC](https://forum.shopware.com/t/update-auf-5-7-2-fehler-bei-filterund-uncaught-syntaxerror-json-parse/89650/3 "2021-09-08T08:46:47Z")

</div>

Manchmal sieht man den Wald vor Bäumen nicht. Plugins lassen sich doch recht einfach im Verhalten ändern.  
z.B. über eine eigene JS-Datei im Theme. Inhalt wie folgt hat das Problem bei uns erstmal beseitigt, hilft bei euch vielleicht auch

```auto
$.overridePlugin('swListingActions',{
    sendListingRequest: function (params, loadFacets, loadProducts, callback, appendDefaults) {
        var me = this;
        if (typeof params === 'object') {
            params = '?' + $.param(params);
        }

        this.resetBuffer();

        $.ajax({
            type: 'get',
            url: this.buildListingUrl(params, loadFacets, loadProducts),
            success: function (textResponse, status, ajaxResponse) {
                var $textResponse = $($.parseHTML(textResponse, document, true)),
                    facets = $textResponse.find('#facets').text(),
                    listing = $textResponse.find('#listing').html(),
                    pagination = $textResponse.find('#pagination').html(),
                    response = {
                        totalCount: parseInt(ajaxResponse.getResponseHeader('Shopware-Listing-Total'))
                    };

                if (facets) {
                    response.facets = JSON.parse(facets);
                }

                if (listing) {
                    response.listing = listing;
                }

                if (pagination) {
                    response.pagination = pagination;
                }

                callback.apply(me, [response, status, ajaxResponse]);
            }
        });
        $.publish('plugin/swListingActions/onGetFilterResult', [this, params]);
    }
});

```

---

<div class="post-metadata">

**Author:** ![Stephan\_Grass](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@Stephan\_Grass](https://forum.shopware.com/u/Stephan_Grass)\
**Post date:** [2. November 2021 um 15:33 UTC](https://forum.shopware.com/t/update-auf-5-7-2-fehler-bei-filterund-uncaught-syntaxerror-json-parse/89650/4 "2021-11-02T15:33:22Z")

</div>

Hi.  
Bei uns ist auch HTML in Freitextfeldern der Hersteller der Verursacher des Fehlers.  
Deine Lösung funktioniert insoweit, dass der Fehler nicht mehr auftritt. Allerdings funktioniert dann die Facettierung nicht mehr.

Habt Ihr dafür ne Lösung gefunden?

Stephan

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [3. November 2021 um 06:50 UTC](https://forum.shopware.com/t/update-auf-5-7-2-fehler-bei-filterund-uncaught-syntaxerror-json-parse/89650/5 "2021-11-03T06:50:50Z")

</div>

Hallo zusammen,

könntet ihr mal schauen, ob dieser Pull Request auf GitHub euer Problem löst?

> <https://github.com/shopware/shopware/pull/2456>
>
> \<!--
> Thank you for contributing to Shopware! Please fill out this description t…emplate to help us to process your pull request.
> 
> Please make sure to fulfil our contribution guideline (https://developers.shopware.com/contributing/contribution-guideline/).
> \--\>
> 
> \### 1. Why is this change necessary?
> widgets/listing/listingCount returns broken json if \`$facets\` contains html tags.
> 
> \### 2. What does this change do, exactly?
> HTML-escapes the json-encoded facets.
> 
> \### 3. Describe each step to reproduce the issue or behaviour.
> Config:
> \\- enable ES
> Plugins:
> \\- TestPlugin (see below, alternatively use SwagEnterpriseSearch and test on search listing)
> Backend settings:
> \\- enable filter\_ajax\_reload
> 
> \<details\>
> \<summary\>TestPlugin/TestPlugin.php\</summary\>
> 
> \`\`\`php
> \<?php
> namespace TestPlugin;
> 
> use Shopware\\Bundle\\SearchBundle\\Criteria;
> use Shopware\\Bundle\\SearchBundle\\FacetResultInterface;
> use Shopware\\Bundle\\SearchBundle\\ProductNumberSearchResult;
> use Shopware\\Bundle\\SearchBundleES\\ResultHydratorInterface;
> use Shopware\\Bundle\\StoreFrontBundle\\Struct\\ShopContextInterface;
> use Shopware\\Components\\Plugin;
> use Symfony\\Component\\DependencyInjection\\ContainerBuilder;
> 
> class TestPlugin extends Plugin {
> public function build(ContainerBuilder $container) {
> parent::build($container);
> $container-\>register(TestHydrator::class)
> -\>addTag('shopware\_search\_es.search\_handler')
> ;
> }
> }
> 
> class TestHydrator implements ResultHydratorInterface {
> public function hydrate(array $elasticResult, ProductNumberSearchResult $result, Criteria $criteria, ShopContextInterface $context) {
> $result-\>addFacet(new class implements FacetResultInterface {
>             
> public string $\_ = '\<b\>';
> 
> public function getFacetName() { return self::class; }
> public function isActive() { return false; }
> public function getLabel() { return self::class; }
> public function getTemplate() { return null; }
> });
> }
> }
> \`\`\`
> \</details\>
> 
> Steps:
> \\- Open category or search listing (e.g. \`/genusswelten/?p=1\`)
> \\- Apply one of the available filters (e.g. "Farbe" "goldig")
> 
> Page hangs at reloading, caused by broken json in \`#facets\` due to \`\<b\>\` tag.
> 
> 
> \### 6. Checklist
> 
> \- \[\] I have written tests and verified that they fail without my change
> \- \[X\] I have squashed any insignificant commits
> \- \[\] This change has comments for package types, values, functions, and non-obvious lines of code
> \- \[X\] I have read the contribution requirements and fulfil them.

Viele Grüße aus Schöppingen  
Michael Telgmann

---

<div class="post-metadata">

**Author:** ![Stephan\_Grass](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@Stephan\_Grass](https://forum.shopware.com/u/Stephan_Grass)\
**Post date:** [3. November 2021 um 07:47 UTC](https://forum.shopware.com/t/update-auf-5-7-2-fehler-bei-filterund-uncaught-syntaxerror-json-parse/89650/6 "2021-11-03T07:47:59Z")

</div>

Hallo Michael,  
Japp, danke. So einfach ist das! Vielleicht sollte man auch öfters auf GitHub vorbei schauen, wenn man Problemchen hat.

Danke für den Hinweis!  
Stephan

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [4. November 2021 um 13:13 UTC](https://forum.shopware.com/t/update-auf-5-7-2-fehler-bei-filterund-uncaught-syntaxerror-json-parse/89650/7 "2021-11-04T13:13:38Z")

</div>

Hallo Stephan,

danke für die Rückmeldung. Der PR wird dann im nächsten Shopware Update enthalten sein.

Viele Grüße aus Schöppingen  
Michael Telgmann
