MySQL Forums
Forum List  »  Newbie

Re: MYSQL TABLE TO JSON OUTPUT... BUT COLUMN ORDER IS NOT COMING PROPERLY
Posted by: Jon Stephens
Date: September 25, 2020 12:21PM

The problem is that Ganesa has encountered one of (a) intended but undocumented behaviour, or (b) a bug. Here's a more detailed example:

mysql> SELECT JSON_OBJECT('user_id', 1,
    -> 'Name', 'Ganesh',
    -> 'DOB', '1980-04-27'
    -> ) AS output;
+-------------------------------------------------------+
| output                                                |
+-------------------------------------------------------+
| {"DOB": "1980-04-27", "Name": "Ganesh", "user_id": 1} |
+-------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT JSON_OBJECT('user_id', 1,
    -> 'DOB', '1980-04-27',
    -> 'Name', 'Ganesh'
    -> ) AS output;
+-------------------------------------------------------+
| output                                                |
+-------------------------------------------------------+
| {"DOB": "1980-04-27", "Name": "Ganesh", "user_id": 1} |
+-------------------------------------------------------+
1 row in set (0.00 sec)
 
mysql> SELECT JSON_OBJECT('name', 'carrot', 'id', 87) AS output;
+------------------------------+
| output                       |
+------------------------------+
| {"id": 87, "name": "carrot"} |
+------------------------------+
1 row in set (0.00 sec)

mysql> SELECT JSON_OBJECT('id', 87, 'name', 'carrot') AS output;
+------------------------------+
| output                       |
+------------------------------+
| {"id": 87, "name": "carrot"} |
+------------------------------+
1 row in set (0.00 sec)

Ganesa,

Please submit a bug report for this issue so someone in Development will look at it and determine whether this is an issue with the documentation or with the function itself.

IMO it's the latter because I don't recall the original spec for this function saying anything about performing a sort by key on the output, but that's not my call to make.


Post a link to the bug report here, and I'll try to remember to keep an eye on it.

Thanks!

Jon Stephens
MySQL Documentation Team @ Oracle

MySQL Dev Zone
MySQL Server Documentation
Oracle

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.