Skip to main content

JSON_ARRAY_FILTER

Introduced or updated: v1.2.644

Filters elements from a JSON array based on a specified Lambda expression, returning only the elements that satisfy the condition. For more information about Lambda expression, see Lambda Expressions.

Syntax

JSON_ARRAY_FILTER(<json_array>, <lambda_expression>)

Return Type

JSON array.

Examples

This example filters the array to return only the strings that start with the letter a, resulting in ["apple", "avocado"]:

SELECT JSON_ARRAY_FILTER(
['apple', 'banana', 'avocado', 'grape']::JSON,
d -> d::String LIKE 'a%'
);

-[ RECORD 1 ]-----------------------------------
json_array_filter(['apple', 'banana', 'avocado', 'grape']::VARIANT, d -> d::STRING LIKE 'a%'): ["apple","avocado"]
Explore Databend Cloud for FREE
Low-cost
Fast Analytics
Easy Data Ingestion
Elastic Scaling
Try it today