Skip to main content

JSON_OBJECT_PICK

Introduced or updated: v1.2.650

Creates a new JSON object containing only the specified keys from the input JSON object. If a specified key doesn't exist in the input object, it is omitted from the result.

Syntax

json_object_pick(<json_object>, <key1> [, <key2>, ...])

Parameters

ParameterDescription
json_objectA JSON object (VARIANT type) from which to pick keys.
key1, key2, ...One or more string literals representing the keys to be included in the result object.

Return Type

Returns a VARIANT containing a new JSON object with only the specified keys and their corresponding values.

Examples

Pick a single key:

SELECT json_object_pick('{"a":1,"b":2,"c":3}'::VARIANT, 'a');
-- Result: {"a":1}

Pick multiple keys:

SELECT json_object_pick('{"a":1,"b":2,"d":4}'::VARIANT, 'a', 'b');
-- Result: {"a":1,"b":2}

Pick with non-existent key (non-existent keys are ignored):

SELECT json_object_pick('{"a":1,"b":2,"d":4}'::VARIANT, 'a', 'c');
-- Result: {"a":1}
Explore Databend Cloud for FREE
Low-cost
Fast Analytics
Easy Data Ingestion
Elastic Scaling
Try it today