1. In the MySQL table, the field type is JSON, and it is allowed to be null. as shown in Figure 1

CREATE TABLE `table` (
`schema` json DEFAULT NULL COMMENT '主题的Schema,包括页面、主题级别、组件级别',
);
2. Since only is_null() is judged in the program, if it is not null, the default is json format. When its value is String(4) “NULL”, the program throws a 500 exception. Displayed as null, indicating that its value is string(4) “null”, which is not as expected. Displayed as (NULL), indicating that its value is NULL, in line with expectations. as shown in Figure 2

3. View the generated sql from the log and confirm that in the record in the change table, the value is assigned tonull. as shown in Figure 3

update
`table`
set
`schema` = 'null',
`checksum` = '0821db9eefeab3d74bbbac6f58cd68e4c8f1b9e2',
`table`.`updated_at` = '2023-04-21 03:41:48'
where
`id` = 432070
4. Print the changes of the relevant variables at the SQL generation. The results are as follows. as shown in Figure 4

$schema1 = $themeAsset->schema;
$schema2 = $this->themeSettingMigration->migrateJsonTemplate($filename, $schema, $themeInstallationTask, $availableVersions);
$themeAsset->schema = json_encode($schema2);
Log::info(
$themeAsset->id,
[
'schema1' => $schema1,
'schema2' => $schema2,
'schema3' => $themeAsset->schema,
]
);
[2023-04-21 11:41:48] local.INFO: 432062 {
"schema1": null,
"schema2": null,
"schema3": "null"
}
5. This concludes that when json_encode(null) is returnednull, and eventually the SQL will be updated to the valuenull. Decide to adjust as follows, add judgment, when not null, only execute json_encode, otherwise return null
$schema = $this->themeSettingMigration->migrateJsonSettingsData($configSettingsDataSchema, $themeInstallationTask, $availableVersions);
$configSettingsData->schema = $schema ? json_encode($schema) : null;
Need long-term technical maintenance or remote troubleshooting?
I am a PHP / Go backend engineer with 15+ years of experience, focused on existing system maintenance, bug fixing, performance optimization, server troubleshooting, WordPress maintenance, and small feature iterations.
If your project is facing any of the following issues, we can start with a small troubleshooting task first:
- ✅ PHP / Laravel / Yii2 legacy systems without active maintenance
- ✅ Go / Gin backend APIs that need troubleshooting or optimization
- ✅ Slow, broken, or unstable WordPress websites
- ✅ Nginx / MySQL / Redis / Linux server issues
- ✅ CDN / Cloudflare / DNS / HTTPS configuration problems
- ✅ Long-term remote technical support or part-time maintenance
More details: About Me & Collaboration
WeChat: 13980074657
Email: shuijingwanwq@gmail.com
Telegram: @shuijingwan
GitHub: https://github.com/shuijingwan

Leave a Reply