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