keys

Returns the top-level keys of an object.

Syntax

keys(<object>)

Arguments

ArgumentTypeDescription
<object>objectObject to inspect.

Returns

Returns array of strings. An empty object returns []. Returns NULL if the input is NULL.

Examples

Inspect top-level keys before selecting fields from events with different payload shapes.

VALUES
    ('evt-17', {'channel': 'web', 'campaign': 'spring'}),
    ('evt-42', {'channel': 'mobile', 'coupon': 'WELCOME'})
SELECT $0 AS event_id, $1 AS payload
SELECT event_id, keys(payload) AS attributes
+----------+------------------------+
| event_id | attributes             |
+----------+------------------------+
| evt-17   | ["campaign","channel"] |
| evt-42   | ["channel","coupon"]   |
+----------+------------------------+

The key order may vary. Use schema to summarize observed keys and types across multiple events.