JSON_EXTRACT

fun JSON_EXTRACT(json: KQLiteColumn<out KQLiteJson?>, vararg path: String): KQLiteColumn<String?>

Extracts one or more values from a JSON string.

This function retrieves a value from the provided JSON column at the specified path. If multiple paths are given, it returns a JSON array containing the values corresponding to each path. If the value at a path does not exist, it is treated as a JSON null.

Example:

val jsonCol = jsonColumn("data") // Column with JSON '{"a": 2, "c": [4, 5, {"f": 7}]}'

// Extract a single value
// SELECT JSON_EXTRACT(data, '$.c') FROM MyTable;
// Result: '[4,5,{"f":7}]'
select(JSON_EXTRACT(jsonCol, "$.c")).from(MyTable).execute()

// Extract multiple values
// SELECT JSON_EXTRACT(data, '$.a', '$.c[2].f') FROM MyTable;
// Result: '[2,7]'
select(JSON_EXTRACT(jsonCol, "$.a", "$.c[2].f")).from(MyTable).execute()

Return

A KQLiteColumn of type String containing the extracted JSON value(s). Returns NULL if the input json is NULL.

Author

MOHAMMAD AZIM ANSARI

Parameters

json

The KQLiteJson column to extract values from.

path

The JSON Path expression to locate a value.

See also