I need to create a list of JSON objects from properties in JSON object using MySQL 5.7. I have this structure:
{
"X": 1,
"Y": 1,
"Z": 55,
"A": 2,
"B": 33
}
I want to have the properties to be separated as objects and sorted by the keys in those objects like this:
[
{"A": 2},
{"B": 3},
{"X": 1},
{"Y": 1},
{"Z": 55}
]
I tried to separate keys and values and maybe then somehow merge it
TRIM(LEADING '[' FROM TRIM(TRAILING ']' FROM JSON_KEYS(letters_and_values))) as letters,
TRIM(LEADING '[' FROM TRIM(TRAILING ']' FROM JSON_EXTRACT(letters_and_values, '$.*'))) as values,
But I feel I'm complicating it. Does anyone know the easiest way to achieve the expected result?