I have a column in a MySQL database that contains a python list
of values in json
format, like this:
Column |
---|
[{"name":"me","color":"red"} , {"name":"you","color":"blue"}] |
I cannot use the json_extract()
function because its format is not exactly the same as json
I want to extract each json
formatted in a new column like this:
First column | Second column |
---|---|
{"Name": "I", "Color": "Red"} | {"name":"you","color":"blue"} |
The following query combined with the string manipulation functions
SUBSTRING_INDEX
,REPLACE
, andCONCAT
will yield the expected results.Here is aworking demonstration of using DBFIDDLE
This gives me the expected output:
Please replace
mytable
with your_actual_table_name andcolumn
with your actual column name. I surrounded the columns with backticks because column is a reserved keyword in sql.You should be able to use JSON_EXTRACT on the example columns included in the question:
Output: