Reputation: 1109
I have the following string: "a,b,c,d"
and I want to convert it into a json array, something like this ["a","b","c","d"]
is there any MySQL 8 function that can achieve this?
Upvotes: 3
Views: 4265
Reputation: 16551
Try:
SELECT
CAST(
CONCAT('["', REPLACE('a,b,c,d', ',', '","'), '"]')
AS JSON
);
See dbfiddle.
Upvotes: 6
Reputation: 823
select json_array("a,b,c,d");
+-----------------------+
| json_array("a,b,c,d") |
+-----------------------+
| ["a,b,c,d"] |
+-----------------------+
Upvotes: -4