core: Unable to serialize to JSON. Bad data found at $.event.result

The problem

using a frontend template card always worked, but since the new json in todays dev throws 2 errors. one on core.entity_registry, and this in the template below

What version of Home Assistant Core has the issue?

2022.7.0.dev20220623

What was the last working version of Home Assistant Core?

2022.7.0.dev20220622

What type of installation are you running?

Home Assistant OS

Integration causing the issue

template websocket

Link to integration documentation on our website

https://next.home-assistant.io/integrations/template https://www.home-assistant.io/integrations/websocket_api/

Diagnostics information

No response

Example YAML snippet

{%- for s in states.binary_sensor -%}
                {%- if s.object_id.endswith("firmware_update") and states(s.entity_id) == 'on' -%}
                    {{
                      { 'type': 'custom:template-entity-row',
                        'entity': "button." + s.object_id.replace("firmware_update", "ota_update"),
                        'state': 'BUTTON',
                        'secondary': state_attr(s.entity_id, 'installed_version')

                      }
                    }},
                {%- endif -%}
              {%- endfor -%}

Anything in the logs that might be useful for us?

Logger: homeassistant.components.websocket_api.messages
Source: components/websocket_api/messages.py:199 
Integration: Home Assistant WebSocket API (documentation, issues) 
First occurred: 08:46:38 (2 occurrences) 
Last logged: 08:46:40

Unable to serialize to JSON. Bad data found at $.event.result={'type': 'custom:template-entity-row', 'entity': 'button.symfonisk_dining_ota_update', 'state': 'BUTTON', 'secondary': '20211109-130223/v1.11.7-g682a0db'},{'type': 'custom:template-entity-row', 'entity': 'button.tester_ota_update', 'state': 'BUTTON', 'secondary': '20211109-130223/v1.11.7-g682a0db'},(<class 'homeassistant.helpers.template.TupleWrapper'>

Additional information

see also https://github.com/home-assistant/core/issues/73882

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (12 by maintainers)

Most upvoted comments

If your goal is to output a list, yes, it should be wrapped as such. The JSON parser is being replaced by a much faster one, but it is compliant with the JSON specifications. It might be that the previous one was more forgiving towards invalid JSON.

Its still useful to fix the exception even if its not a new problem

Right thx. So I changed those to use the [] on all templates that use it.

will close this then. The other one #73882 is still a mystery as to the why.