Mysql 5.7 native json support - order of control keys in json_insert function

I am encountering problems with ordering json keys when pasting using json_insert function.

I have sorted entries below

"AIR", "AIR Express"

CFR, Cost and Freight

"FH", "Free House"

"UN", "United Nations"

"UPS", "United Parcel Service"

After converting the above entries to json using the json_insert function, I see the results below

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

but I want json to store the keys in the order I insert. Although I could feel that he was trying to maintain order based on the length of the key characters. But how can I get rid of to get the keys aligned in order.

+6
source share
2 answers

This is sad, but there is currently no way to preserve the order of the original keys.

Normalization, union, and automatic packing of JSON values

The normalization performed by MySQL also sorts the keys for the JSON object (in order to improve search efficiency). The result of this order is subject to change and is not guaranteed to be consistent across releases. In addition, extra spaces between keys, values, or elements in the source document are discarded.

+7

, , , , , . , ,

{ " 1: FH": " ", " 2: ": " ", " 3: AIR": "AIR Express", " 4: CFR": " ", " 5: UPS": "United Parcel Service" }

, , - , , , , JS PHP. !

-1

Source: https://habr.com/ru/post/1651001/


All Articles