json_object_keys function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Returns all the keys of the outermost JSON object as an array.

Syntax

json_object_keys(jsonObject)

Arguments

  • jsonObject: A STRING expression of a valid JSON array format.

Returns

An ARRAY<STRING>.

If ‘jsonObject’ is any other valid JSON string, an invalid JSON string or an empty string, the function returns NULL.

Examples

> SELECT json_object_keys('{}');
  []
> SELECT json_object_keys('{"key": "value"}');
  [key]
> SELECT json_object_keys('{"f1":"abc","f2":{"f3":"a", "f4":"b"}}');
  [f1,f2]