I have a column in MySQL database which contains a python list
of json
formatted values like below:
Column |
---|
[{"name":"me","color":"red"} , {"name":"you","color":"blue"}] |
I could not use json_extract()
function because it’s not formatted exactly as a json
I want to extract each of json
formatted in a new column like below:
First_column | Second_column |
---|---|
{"name":"me","color":"red"} | {"name":"you","color":"blue"} |
2
Answers
The following query with combination of string manipulation functions
SUBSTRING_INDEX
,REPLACE
andCONCAT
shall get you the expected result.Here is a working demo using DBFIDDLE
This gives me expected output as :
Please replace the
mytable
with your_actual_table_name andcolumn
with your actual column name. I have surrounded column with backticks as column is a reserved keyword in sql.You should be able to use JSON_EXTRACT on the sample column included in your question:
Outputs: