MySQL Forums
Forum List  »  Newbie

MYSQL TABLE TO JSON OUTPUT... BUT COLUMN ORDER IS NOT COMING PROPERLY
Posted by: GANESA KUMAR
Date: September 25, 2020 06:46AM

Query : JSON format output from table

SELECT JSON_OBJECT('user_id', 1,
'Name', 'Ganesh',
'DOB', '1980-04-27'
) AS OUTPUT


Expected output should be:
{
"user_id" : 1,
"Name" : "Ganesh",
"DOB" : "1980-04-27"


}

But what i got

{
"DOB" : "1980-04-27",
"Name" : "Ganesh",
"user_id" : 1
}

Problem is column order. Column order in JSON should User_id,name and DOB.
But am getting like DOB,Name and User_id.

Anyone can help me to order the output as expected.

Note : Here i have given simple example, actually my query will have multiple array objects also.. so i did not tried any user defined procedure to create JSON output.

If anybody can help to order the column in JSON_OBJECT would be very greatful for me instead of writing any other script.

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.