The key order of data under the JSON column type written to the MySQL 5.7 table is scrambled and analyzed
1. The original format of JSON data is as follows. The order of its key names is as follows: TexGetCux, QKGYGZ2st, YE9GC1KXT, Q1YQZ2RBI. as shown in Figure 1
{
"sections": {
"TexGEtcUx": {
"type": "main-index-carousel",
"settings": {
"loop": true,
"autoplay": true,
"height": "full",
"interval": 5
},
"blocks": {
"slide-0": {
"type": "slide",
"settings": {
"image": "",
"url": "/",
"align": "center",
"title": "Image with text overlay",
"description": "Use overlay text to give your customers insight into your brand. Select imagery and text that relates to your style and story.",
"button": "Shop Now",
"opacity": 100,
"button_background_color": "#ffffff",
"button_color": "#000000",
"color": "#ffffff"
}
},
"slide-1": {
"type": "slide",
"settings": {
"image": "",
"url": "/",
"align": "center",
"title": "Image with text overlay",
"description": "Use overlay text to give your customers insight into your brand. Select imagery and text that relates to your style and story.",
"button": "Shop Now",
"opacity": 100,
"button_background_color": "#ffffff",
"button_color": "#000000",
"color": "#ffffff"
}
}
}
},
"QkGyGZ2ST": {
"type": "collections"
},
"yE9gC1kxT": {
"type": "products"
},
"Q1yqz2RBi": {
"type": "apps",
"blocks": {
"newsletter": {
"type": "internal/newsletter/blocks/newsletter"
}
}
}
}
}
2. Execute the code to insert the database as follows, print $extra[‘schema’]
$asset = ThemeAsset::withoutVersion(function () use($predicate, $extra) {
if ($predicate['asset_key'] == 'pages/index.blade.php') {
print_r($extra['schema']);
exit;
}
return ThemeAsset::updateOrCreate(
$predicate,
$extra
);
});
3. Print $extra[‘schema’], which is equal to the original format of JSON data. as shown in Figure 2
{
"sections": {
"TexGEtcUx": {
"type": "main-index-carousel",
"settings": {
"loop": true,
"autoplay": true,
"height": "full",
"interval": 5
},
"blocks": {
"slide-0": {
"type": "slide",
"settings": {
"image": "",
"url": "/",
"align": "center",
"title": "Image with text overlay",
"description": "Use overlay text to give your customers insight into your brand. Select imagery and text that relates to your style and story.",
"button": "Shop Now",
"opacity": 100,
"button_background_color": "#ffffff",
"button_color": "#000000",
"color": "#ffffff"
}
},
"slide-1": {
"type": "slide",
"settings": {
"image": "",
"url": "/",
"align": "center",
"title": "Image with text overlay",
"description": "Use overlay text to give your customers insight into your brand. Select imagery and text that relates to your style and story.",
"button": "Shop Now",
"opacity": 100,
"button_background_color": "#ffffff",
"button_color": "#000000",
"color": "#ffffff"
}
}
}
},
"QkGyGZ2ST": {
"type": "collections"
},
"yE9gC1kxT": {
"type": "products"
},
"Q1yqz2RBi": {
"type": "apps",
"blocks": {
"newsletter": {
"type": "internal/newsletter/blocks/newsletter"
}
}
}
}
}
4. View the data written in the table, and suspect that the order of the keys of its JSON is arranged in alphabetical order. Q1YQZ2RBI, QKGYGZ2ST, TEXGetCux, YE9GC1KXT. And the order of the keys of the sub-JSON structure inside its internal sub-JSON structure has also changed.
{
"sections": {
"Q1yqz2RBi": {
"type": "apps",
"blocks": {
"newsletter": {
"type": "internal/newsletter/blocks/newsletter"
}
}
},
"QkGyGZ2ST": {
"type": "collections"
},
"TexGEtcUx": {
"type": "main-index-carousel",
"blocks": {
"slide-0": {
"type": "slide",
"settings": {
"url": "/",
"align": "center",
"color": "#ffffff",
"image": "",
"title": "Image with text overlay",
"button": "Shop Now",
"opacity": 100,
"description": "Use overlay text to give your customers insight into your brand. Select imagery and text that relates to your style and story.",
"button_color": "#000000",
"button_background_color": "#ffffff"
}
},
"slide-1": {
"type": "slide",
"settings": {
"url": "/",
"align": "center",
"color": "#ffffff",
"image": "",
"title": "Image with text overlay",
"button": "Shop Now",
"opacity": 100,
"description": "Use overlay text to give your customers insight into your brand. Select imagery and text that relates to your style and story.",
"button_color": "#000000",
"button_background_color": "#ffffff"
}
}
},
"settings": {
"loop": true,
"height": "full",
"autoplay": true,
"interval": 5
}
},
"yE9gC1kxT": {
"type": "products"
}
}
}
5. After modifying the type of the table column to text, the order of JSON is consistent with the original one. as shown in Figure 3

![打印 $extra['schema'] ,其等于 json 数据的原始格式](https://www.shuijingwanwq.com/wp-content/uploads/2022/09/2-6.png)
