Spark SQL - Return JSON Object Keys (json_object_keys)

visibility 25 access_time 23 days ago languageEnglish timeline Stats
timeline Stats
Page index 1.04
more_horiz

Spark SQL function json_object_keys can be used to return an array of the outmost JSON object's keys. The input can be a valid JSON string too.

Code snippet

spark-sql> select json_object_keys('{}');
  []
spark-sql> select json_object_keys('{"key": "value"}');
  ["key"]
spark-sql> select json_object_keys('{"key1":"value1","key2":{"key3":"value3", "key4":"value4"}}');
  ["key1","key2"]
infoThis function is only available from Spark 3.1.0.

Other references

Spark SQL - Extract Value from JSON String

Spark SQL - Convert Object to JSON String

copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

More from Kontext
Spark SQL - Standard Deviation Calculation
visibility 2,702
thumb_up 0
access_time 2 years ago
Spark SQL - flatten Function
visibility 19
thumb_up 0
access_time 28 days ago
Spark SQL - flatten Function