json - Mysql 5.7 原生 json 支持 - 在 json_insert 函数中控制键顺序

标签 json mysql-5.7

我在使用 json_insert 函数插入时遇到 json 键排序问题。

我有如下排序的记录

“航空”、“航空 express ”

“CFR”、“成本加运费”

“FH”、“自由屋”

"联合国"、"联合国"

“UPS”、“联合包裹服务”

使用 json_insert 函数将上述记录转换为 json 后,我看到的结果如下

{"FH":"Free house", "UN": "United Nations", "AIR": "AIR Express", "CFR": "Cost and Freight", "UPS": "United Parcel Service"

但我希望 json 按照我插入的顺序维护 key 。虽然我可以感觉到它正在尝试根据键的字符长度来维护顺序。但是我怎样才能摆脱让键按顺序对齐。

最佳答案

这很可悲,但目前无法保持原始 key 顺序。

Normalization, Merging, and Autowrapping of JSON Values

The normalization performed by MySQL also sorts the keys of a JSON object (for the purpose of making lookups more efficient). The result of this ordering is subject to change and not guaranteed to be consistent across releases. In addition, extra whitespace between keys, values, or elements in the original document is discarded.

关于json - Mysql 5.7 原生 json 支持 - 在 json_insert 函数中控制键顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56146086/

相关文章:

mysql - 为什么 COUNT() 只显示一行表格?

MySQL产品存储-架构

jquery - 使用 jQuery 匿名上传图像到 Imgur API v3?

json - 如何在 golang 自定义结构类型中绑定(bind) json stringify 数据?

mysql - 将 JSON 文件导入 MySQL 5.7

Mysql - 错误 1726 (HY000) 在行... : Storage engine 'InnoDB' does not support system tables

javascript - this.state.json.map 不是一个函数

javascript - 获取html对象中的json数据,对象来自ajax获取响应

java - 创建 json 对象

mysql - mysql.user 表中的 max_connections 列有什么用?