I have json data and I am trying to put that data in different columns in oracle. Issue is one of the column sometimes contains an array and sometimes contain string. I know there is different command to put json array to column but if the column is populated with string sometimes and array sometimes, how do I write sql so that it fetch all data -
SELECT id,array1
FROM (
select '{
"data": [
{
"id": 1,
"array1": [ "INFO", "ABC", ]
},
{
"id": 2,
"array1": "TEST",
}
]
}' AS JSON_DATA
FROM DUAL
) I,
json_table(
i.JSON_DATA ,
'$.data[*]'
COLUMNS (
array1 varchar2(4000) FORMAT JSON path'$."array1"',
ID varchar2(4000) path '$."id"'
)
) a
Output from the sql:
ID ARRAY1
1 ["INFO","ABC"]
2
Desired Ouput :
ID ARRAY1
1 ["INFO","ABC"]
2 TEST