JSON_OBJECT_KEYS

Returns an Array containing the list of keys in the input Variant OBJECT.

Analyze Syntax

func.json_object_keys(<variant>)

Analyze Example

func.json_object_keys(func.parse_json(parse_json('{"a": 1, "b": [1,2,3]}')), func.json_object_keys(func.parse_json(parse_json('{"b": [2,3,4]}'))
┌─────────────────────────────────────────────────────────────────┐
       id         json_object_keys(var)  json_object_keys(var) 
├────────────────┼────────────────────────┼───────────────────────┤
              1  ["a","b"]               ["a","b"]             
              2  ["b"]                   ["b"]                 
└─────────────────────────────────────────────────────────────────┘

SQL Syntax

JSON_OBJECT_KEYS(<variant>)

Arguments

ArgumentsDescription
<variant>The VARIANT value that contains an OBJECT

Aliases

Return Type

Array<String>

SQL Examples

CREATE TABLE IF NOT EXISTS objects_test1(id TINYINT, var VARIANT);

INSERT INTO
  objects_test1
VALUES
  (1, parse_json('{"a": 1, "b": [1,2,3]}'));

INSERT INTO
  objects_test1
VALUES
  (2, parse_json('{"b": [2,3,4]}'));

SELECT
  id,
  object_keys(var),
  json_object_keys(var)
FROM
  objects_test1;

┌────────────────────────────────────────────────────────────┐
       id         object_keys(var)  json_object_keys(var) 
├────────────────┼───────────────────┼───────────────────────┤
              1  ["a","b"]          ["a","b"]             
              2  ["b"]              ["b"]                 
└────────────────────────────────────────────────────────────┘
Last modified June 12, 2024 at 4:51 PM EST: adding JSON method updates (a7607f7)