Reputation: 3098
I have this sample data (from Athena)
SELECT DISTINCT m.key
FROM (VALUES JSON '{"name":"project1","completed":false}', JSON '{"name":"project1","completed":false}',JSON '{"name":"project1","completed":false}')
example_table(json_column)
CROSS JOIN UNNEST (map_keys(CAST(json_column AS map<varchar,json>))) AS m(key);
WITH dataset AS (
SELECT '{"name": "Susan Smith",
"org": "engineering",
"projects": [{"name":"project1", "completed":false},
{"name":"project2", "completed":true}]}'
AS blob
)
select * from dataset
This will generate the below output.
{"name": "Susan Smith", "org": "engineering", "projects": [{"name":"project1", "completed":false}, {"name":"project2", "completed":true}]}
I want to extract Key from the output.
output
------
name
org
projects
Could someone help on this?
edited this question with proper JSON.
Upvotes: 1
Views: 4775
Reputation: 20710
Based on discussion in comments, this
map_keys(CAST(json_column AS map<varchar,json>))
needs to be replaced with
map_keys(CAST(CAST(json_column AS JSON) AS map<varchar,json>))
Upvotes: 1