Issue Bug Closed

#106638Double json_encode when persisting an Extbase model property with database field type "JSON"

Devid Messner 04/30/25, 08:35 updated 08/11/26, 08:46

Description

When persisting an Extbase model with a property mapped to a database field of type JSON, the value gets double-encoded with json_encode.

Background: In typo3/cms-extbase/Classes/Persistence/Generic/Backend.php → persistObject(), all property values must either be strings or be converted to strings. This means an array or object must already be passed as a JSON string.
Additionally, in vendor/typo3/cms-core/Classes/Database/Connection.php → ensureDatabaseValueTypes(), the database field type is checked. If the type is json, the string is passed through json_encode again — specifically in vendor/doctrine/dbal/src/Types/JsonType.php → convertToDatabaseValue().
As a result, the field (TCA type json) is no longer recognized as valid JSON in the backend.

Workaround: Change the field type in the database from json to longtext.

Question: Is there a recommended solution or approach to preserve the use of the json field type?

Reviews 5

History 545

Show 220 earlier messages
  1. Stefan Bürk commented and changed status New Accepted assigned to Stefan Bürk <span data-processor="relativetime" data-value="2025-04-30T17:10:45+00:00" > 04/30/25, 17:10 </span>

    Extbase never had “json” support, and misses TCA type=json (DB type json) support.
    At least the double encoding should be prevented in the first step and as “bugfix”,
    literally ignoring TCA/DB Type json for now.

    In v14 support for extbase (DECODE + ENCODE) can be added in a dedicated step,
    which is not really suitable as bugfix due to changes required for models I guess.

  2. Gerrit Code Review pushed patch set 1 for main to change 89293 status Accepted Under Review <span data-processor="relativetime" data-value="2025-05-04T19:36:18+00:00" > 05/04/25, 19:36 </span>

  1. Stefan Bürk commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-07-23T07:55:09+00:00" > 07/23/26, 07:55 </span>

    Applied in changeset commit:5ca75e82645c82397bde145b12b2ba7c334ca195.