The reordering of Json-Content is already an known issue while sending AJAX Request, but I wasn't aware that the same happens while inserting Json-content into an Mysql Table with JSON type.
In this case the mysql server also orders its content before saving.
before:
{"c":3, "b":2, "a":1}
after:
{"a":1, "b":2, "c":3}
Suppose I would like to prevent this ordering for some purpose... Is there any possibility to disable the ordering without adapting the Json data itself?
The key to this is to serialize this > then store it > retrieve > then parse
For example: First store object as a string
var jsonDataStringed = JSON.stringify(myJsonData);
INSERT INTO MY_TABLE(id,jsonDataStringed);
then to retrieve the string and change it back to object
db.sequelize.query(`SELECT * FROM MY_TABLE`);
var myJsonData = JSON.parse(db[0])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With