I have a MySQL 5.7 database table that stores a piece of information as JSON. The JSON structure for these records is something like this, stored in a column called, for instance my_json
:
{
"someString": "string",
"someArray:": ["array", "of", "stuff"]
}
I can select the individual parts of this easily with a query like this:
SELECT mt.some_field AS some_field,
JSON_EXTRACT(mt.my_json, "$.someString") AS some_string,
JSON_EXTRACT(mt.my_json, "$.someArray") AS some_array
FROM my_table AS mt
and I get a nice response with my JSON object split up into two separate columns.
What I would like to do though, is convert the JSON_EXTRACTed someArray
property into a comma separated string. So rather than a column called some_array
with a value like ["array", "of", "stuff"]
, I want to have a column called some_array
with a value like array, of, stuff
.
Can anyone help me figure out the right SQL to do this? (Again, using MySQL 5.7)
Thanks!!