I have been trying to get a JSON object from my DB in the format that I wanted it so I ran the following sql query:
SELECT PROJECTS.key_code AS CODE, PROJECTS.name AS Name,
PROJECTS.date AS Date, PROJECTS.descr AS Description
FROM PROJECTS LEFT JOIN ACCESS
ON PROJECTS.key_code = ACCESS.key_code
WHERE ACCESS.Ukey_code = '5d8hd5' FOR JSON PATH, WITHOUT_ARRAY_WRAPPER;
and the result of the query as follow:
{
"Code": "h5P93G",
"Name": "Project1 test name",
"Date": "2017-09-03",
"Description": "This is a test description 1"
},
"Code": "KYJ482",
"Name": "Project2 test name",
"Date": "2018-10-25",
"Description": "This is a test description 2"
}
but actually what I want is different. The JSON object should look like:
{
"h5P93G": {
"Name": "Project1 test name",
"Date": "2017-09-03",
"Description": "This is a test description 1"
},
"KYJ482": {
"Name": "Project2 test name",
"Date": "2018-10-25",
"Description": "This is a test description 2"
},
}
So, how I could get this JSON object?