Skip to content
Advertisement

Get JSON object keys as array in Presto/Trino

I have JSON data like this in one of my columns

and I would like to run a query that returns the keys as an array

Advertisement

Answer

Convert your JSON into a MAP and then use map_keys():

Use json_parse() if your JSON column is of type VARCHAR

Output:

_col0
bar, foo
foo
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement