I have a column called users with this JSON.
{
"[email protected]":[1.0,5.95],
"[email protected]":[2.0,30.733],
"[email protected]":[1.0,4.433],
"[email protected]":[2.0,16.25]
}
I want to unwrap it in this way
splitUsers firstValue secondValue [email protected] 1.0 5.95 [email protected] 2.0 30.733 [email protected] 1.2 4.433 [email protected] 2.0 16.25
I managed to split the emails with query below, however I can't get the array values as in seperate columns.
select * from tableName
CROSS JOIN UNNEST(SPLIT(array_join(map_keys(CAST(json_parse(users) AS MAP(VARCHAR, JSON))), ', '),','))
AS t (splitUsers)
Is there a way to achieve what I'm looking for?
You seem to be very close, one of the options would be using json extract functions (for example
json_extract_scalar
) on the unnested value (after casting tomap
, note the succinct syntax for theunnest
):Output: