Skip to content
Advertisement

Extract data from JSON column

i want to extract a value from a json column.

The schema is (- first level, — second level):

Currently i extract a value this way:

Is there a better way to handle the task?

Advertisement

Answer

Assuming that:

  • event_params is an array of struct type.
  • user_id is a unique key in each event_params

Following code style would be possible:

You can define a UDF to extract a value from an array of struct with key-value pair. Google provides some useful UDFs in public.

Above queries will return same output:

enter image description here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement