Having this in column named "value" on table named "test" with varchar data type:
'{"3": "3", "2": "7", "6": "1", "1": "2", "5": "5"}'
the output I need:
col1 col2
3 3
2 7
6 1
1 2
5 5
I'm having difficulties to parse json as it's seems that only version 8 provides ability to work with json properly.
Maybe the are some thoughts how to solve it and extract key and values dynamically without hardcoding key as following in col1 and col2:
select 1 as 'col1', TRIM(BOTH '"' FROM (JSON_EXTRACT(value, '$."1"'))) 'col2'
from test
union all
select 2, TRIM(BOTH '"' FROM (JSON_EXTRACT(value, '$."2"')))
from test
union all
select 3, TRIM(BOTH '"' FROM (JSON_EXTRACT(value, '$."3"')))
from test
union all
select 5, TRIM(BOTH '"' FROM (JSON_EXTRACT(value, '$."5"')))
from test
union all
select 6, TRIM(BOTH '"' FROM (JSON_EXTRACT(value, '$."6"')))
from test