Skip to main content

Structured & Semi-Structured Functions

Structured and semi-structured functions in Databend enable efficient processing of arrays, objects, maps, JSON, and other structured data formats. These functions provide comprehensive capabilities for creating, parsing, querying, transforming, and manipulating structured and semi-structured data.

JSON Functions

FunctionDescriptionExample
PARSE_JSONParses a JSON string into a variant valuePARSE_JSON('[1,2,3]')
CHECK_JSONValidates if a string is valid JSONCHECK_JSON('{"a":1}')
JSON_TYPEOFReturns the type of a JSON valueJSON_TYPEOF(PARSE_JSON('[1,2,3]'))
JSON_TO_STRINGConverts a JSON value to a stringJSON_TO_STRING(PARSE_JSON('{"a":1}'))
JSON_PATH_EXISTSChecks if a JSON path existsJSON_PATH_EXISTS(json_obj, '$.name')
JSON_PATH_MATCHMatches JSON values against a path patternJSON_PATH_MATCH(json_obj, '$.age')
JSON_PATH_QUERYQueries JSON data using JSONPathJSON_PATH_QUERY(json_obj, '$.items[*]')
JSON_PATH_QUERY_ARRAYQueries JSON data and returns results as an arrayJSON_PATH_QUERY_ARRAY(json_obj, '$.items')
JSON_PATH_QUERY_FIRSTReturns the first result from a JSON path queryJSON_PATH_QUERY_FIRST(json_obj, '$.items[*]')
JSON_EXTRACT_PATH_TEXTExtracts text value from JSON using pathJSON_EXTRACT_PATH_TEXT(json_obj, 'name')
GETGets a value from a JSON object by key or array by indexGET(PARSE_JSON('[1,2,3]'), 0)
GET_PATHGets a value from a JSON object using a path expressionGET_PATH(json_obj, 'user.name')
GET_IGNORE_CASEGets a value with case-insensitive key matchingGET_IGNORE_CASE(json_obj, 'NAME')
JSON_EACHExpands JSON object into key-value pairsJSON_EACH(PARSE_JSON('{"a":1,"b":2}'))
JSON_ARRAY_ELEMENTSExpands JSON array into individual elementsJSON_ARRAY_ELEMENTS(PARSE_JSON('[1,2,3]'))
JSON_PRETTYFormats JSON with proper indentationJSON_PRETTY(PARSE_JSON('{"a":1}'))
STRIP_NULL_VALUERemoves null values from JSONSTRIP_NULL_VALUE(PARSE_JSON('{"a":1,"b":null}'))

Array Functions

FunctionDescriptionExample
ARRAY_CONSTRUCTCreates an array from individual valuesARRAY_CONSTRUCT(1, 2, 3)
RANGEGenerates an array of sequential numbersRANGE(1, 5)
GETGets an element from an array by indexGET(PARSE_JSON('[1,2,3]'), 0)
ARRAY_GETAlias for GET functionARRAY_GET([1,2,3], 1)
CONTAINSChecks if an array contains a specific valueCONTAINS([1,2,3], 2)
ARRAY_CONTAINSChecks if an array contains a specific valueARRAY_CONTAINS([1,2,3], 2)
ARRAY_APPENDAppends an element to the end of an arrayARRAY_APPEND([1,2], 3)
ARRAY_PREPENDPrepends an element to the beginning of an arrayARRAY_PREPEND([2,3], 1)
ARRAY_INSERTInserts an element at a specific positionARRAY_INSERT([1,3], 1, 2)
ARRAY_REMOVERemoves all occurrences of a specified elementARRAY_REMOVE([1,2,2,3], 2)
ARRAY_REMOVE_FIRSTRemoves the first element from an arrayARRAY_REMOVE_FIRST([1,2,3])
ARRAY_REMOVE_LASTRemoves the last element from an arrayARRAY_REMOVE_LAST([1,2,3])
ARRAY_CONCATConcatenates multiple arraysARRAY_CONCAT([1,2], [3,4])
ARRAY_SLICEExtracts a portion of an arrayARRAY_SLICE([1,2,3,4], 1, 2)
SLICEAlias for ARRAY_SLICE functionSLICE([1,2,3,4], 1, 2)
ARRAYS_ZIPCombines multiple arrays element-wiseARRAYS_ZIP([1,2], ['a','b'])
ARRAY_DISTINCTReturns unique elements from an arrayARRAY_DISTINCT([1,2,2,3])
ARRAY_UNIQUEAlias for ARRAY_DISTINCT functionARRAY_UNIQUE([1,2,2,3])
ARRAY_INTERSECTIONReturns common elements between arraysARRAY_INTERSECTION([1,2,3], [2,3,4])
ARRAY_EXCEPTReturns elements in first array but not in secondARRAY_EXCEPT([1,2,3], [2,3])
ARRAY_OVERLAPChecks if arrays have common elementsARRAY_OVERLAP([1,2], [2,3])
ARRAY_TRANSFORMApplies a function to each array elementARRAY_TRANSFORM([1,2,3], x -> x * 2)
ARRAY_FILTERFilters array elements based on a conditionARRAY_FILTER([1,2,3,4], x -> x > 2)
ARRAY_REDUCEReduces array to a single value using aggregationARRAY_REDUCE([1,2,3], 0, (acc, x) -> acc + x)
ARRAY_AGGREGATEAggregates array elements using a functionARRAY_AGGREGATE([1,2,3], 'sum')
ARRAY_COMPACTRemoves null values from an arrayARRAY_COMPACT([1, NULL, 2, NULL, 3])
ARRAY_FLATTENFlattens nested arrays into a single arrayARRAY_FLATTEN([[1,2], [3,4]])
ARRAY_REVERSEReverses the order of array elementsARRAY_REVERSE([1,2,3])
ARRAY_INDEXOFReturns the index of first occurrence of an elementARRAY_INDEXOF([1,2,3,2], 2)
UNNESTExpands an array into individual rowsUNNEST([1,2,3])

Object Functions

FunctionDescriptionExample
OBJECT_CONSTRUCTCreates a JSON object from key-value pairsOBJECT_CONSTRUCT('name', 'John', 'age', 30)
OBJECT_CONSTRUCT_KEEP_NULLCreates a JSON object keeping null valuesOBJECT_CONSTRUCT_KEEP_NULL('a', 1, 'b', NULL)
OBJECT_KEYSReturns all keys from a JSON object as an arrayOBJECT_KEYS(PARSE_JSON('{"a":1,"b":2}'))
OBJECT_INSERTInserts or updates a key-value pair in a JSON objectOBJECT_INSERT(json_obj, 'new_key', 'value')
OBJECT_DELETERemoves a key-value pair from a JSON objectOBJECT_DELETE(json_obj, 'key_to_remove')
OBJECT_PICKCreates a new object with only specified keysOBJECT_PICK(json_obj, 'name', 'age')

Map Functions

FunctionDescriptionExample
MAP_CATCombines multiple maps into a single mapMAP_CAT({'a':1}, {'b':2})
MAP_KEYSReturns all keys from a map as an arrayMAP_KEYS({'a':1, 'b':2})
MAP_VALUESReturns all values from a map as an arrayMAP_VALUES({'a':1, 'b':2})
MAP_SIZEReturns the number of key-value pairs in a mapMAP_SIZE({'a':1, 'b':2})
MAP_CONTAINS_KEYChecks if a map contains a specific keyMAP_CONTAINS_KEY({'a':1}, 'a')
MAP_INSERTInserts a key-value pair into a mapMAP_INSERT({'a':1}, 'b', 2)
MAP_DELETERemoves a key-value pair from a mapMAP_DELETE({'a':1, 'b':2}, 'b')
MAP_TRANSFORM_KEYSApplies a function to each key in a mapMAP_TRANSFORM_KEYS(map, k -> UPPER(k))
MAP_TRANSFORM_VALUESApplies a function to each value in a mapMAP_TRANSFORM_VALUES(map, v -> v * 2)
MAP_FILTERFilters key-value pairs based on a predicateMAP_FILTER(map, (k, v) -> v > 10)
MAP_PICKCreates a new map with only specified keysMAP_PICK({'a':1, 'b':2, 'c':3}, 'a', 'c')

Type Conversion Functions

FunctionDescriptionExample
AS_BOOLEANConverts a VARIANT value to BOOLEANAS_BOOLEAN(PARSE_JSON('true'))
AS_INTEGERConverts a VARIANT value to BIGINTAS_INTEGER(PARSE_JSON('42'))
AS_FLOATConverts a VARIANT value to DOUBLEAS_FLOAT(PARSE_JSON('3.14'))
AS_DECIMALConverts a VARIANT value to DECIMALAS_DECIMAL(PARSE_JSON('12.34'))
AS_STRINGConverts a VARIANT value to STRINGAS_STRING(PARSE_JSON('"hello"'))
AS_BINARYConverts a VARIANT value to BINARYAS_BINARY(TO_BINARY('abcd')::VARIANT)
AS_DATEConverts a VARIANT value to DATEAS_DATE(TO_DATE('2025-10-11')::VARIANT)
AS_ARRAYConverts a VARIANT value to ARRAYAS_ARRAY(PARSE_JSON('[1,2,3]'))
AS_OBJECTConverts a VARIANT value to OBJECTAS_OBJECT(PARSE_JSON('{"a":1}'))

Type Predicate Functions

FunctionDescriptionExample
IS_ARRAYChecks if a JSON value is an arrayIS_ARRAY(PARSE_JSON('[1,2,3]'))
IS_OBJECTChecks if a JSON value is an objectIS_OBJECT(PARSE_JSON('{"a":1}'))
IS_STRINGChecks if a JSON value is a stringIS_STRING(PARSE_JSON('"hello"'))
IS_INTEGERChecks if a JSON value is an integerIS_INTEGER(PARSE_JSON('42'))
IS_FLOATChecks if a JSON value is a floating-point numberIS_FLOAT(PARSE_JSON('3.14'))
IS_BOOLEANChecks if a JSON value is a booleanIS_BOOLEAN(PARSE_JSON('true'))
IS_NULL_VALUEChecks if a JSON value is nullIS_NULL_VALUE(PARSE_JSON('null'))
Explore Databend Cloud for FREE
Low-cost
Fast Analytics
Easy Data Ingestion
Elastic Scaling
Try it today