Skip to main content

JSON_EXISTS_KEY

Checks whether a JSON object contains one or more keys.

  • JSON_EXISTS_KEY tests a single key.
  • JSON_EXISTS_ANY_KEYS accepts an array of keys and returns TRUE when at least one key exists.
  • JSON_EXISTS_ALL_KEYS returns TRUE only when every key in the array exists.

Syntax

JSON_EXISTS_KEY(<variant>, <key>)
JSON_EXISTS_ANY_KEYS(<variant>, <array_of_keys>)
JSON_EXISTS_ALL_KEYS(<variant>, <array_of_keys>)

Return Type

BOOLEAN

Examples

SELECT JSON_EXISTS_KEY(PARSE_JSON('{"a":1,"b":2}'), 'b') AS has_b;

┌──────┐
│ has_b│
├──────┤
true
└──────┘
SELECT JSON_EXISTS_ANY_KEYS(PARSE_JSON('{"a":1,"b":2}'), ['x','b']) AS any_key;

┌────────┐
│ any_key│
├────────┤
true
└────────┘
SELECT JSON_EXISTS_ALL_KEYS(PARSE_JSON('{"a":1,"b":2}'), ['a','b','c']) AS all_keys;

┌────────┐
│ all_keys│
├────────┤
false
└────────┘
SELECT JSON_EXISTS_ALL_KEYS(PARSE_JSON('{"a":1,"b":2}'), ['a','b']) AS all_keys;

┌────────┐
│ all_keys│
├────────┤
true
└────────┘
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today