Documentation Index
Fetch the complete documentation index at: https://private-7c7dfe99-page-updates.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Types of JSON functions
There are two sets of functions to parse JSON:simpleJSON*(visitParam*) which is made for parsing a limited subset of JSON extremely fast.JSONExtract*which is made for parsing ordinary JSON.
simpleJSON (visitParam) functions
ClickHouse has special functions for working with simplified JSON. All these JSON functions are based on strong assumptions about what the JSON can be. They try to do as little as possible to get the job done as quickly as possible. The following assumptions are made:- The field name (function argument) must be a constant.
- The field name is somehow canonically encoded in JSON. For example:
simpleJSONHas('{"abc":"def"}', 'abc') = 1, butsimpleJSONHas('{"\\u0061\\u0062\\u0063":"def"}', 'abc') = 0 - Fields are searched for on any nesting level, indiscriminately. If there are multiple matching fields, the first occurrence is used.
- The JSON does not have space characters outside of string literals.
JSONExtract functions
These functions are based on simdjson, and designed for more complex JSON parsing requirements.Case-Insensitive JSONExtract Functions
These functions perform ASCII case-insensitive key matching when extracting values from JSON objects. They work identically to their case-sensitive counterparts, except that object keys are matched without regard to case. When multiple keys match with different cases, the first match is returned.These functions may be less performant than their case-sensitive counterparts, so use the regular JSONExtract functions if possible.
JSONAllPaths
Introduced in: v24.8.0 Returns the list of all paths stored in each row in JSON column. Syntaxjson— JSON column.JSON
Array(String)
Examples
Usage example
Query
Response
JSONAllPathsWithTypes
Introduced in: v24.8.0 Returns the list of all paths and their data types stored in each row in JSON column. Syntaxjson— JSON column.JSON
Map(String, String)
Examples
Usage example
Query
Response
JSONAllValues
Introduced in: v26.4.0 Returns all values from each row in a JSON column as an array of strings. Values are serialized in their text representation and ordered by their path names. Syntaxjson— JSON column.JSON
Array(String)
Examples
Usage example
Query
Response
JSONArrayLength
Introduced in: v23.2.0 Returns the number of elements in the outermost JSON array. The function returnsNULL if input JSON string is invalid.
Syntax
JSON_ARRAY_LENGTH
Arguments
json— String with valid JSON.String
json is a valid JSON array string, otherwise returns NULL. Nullable(UInt64)
Examples
Usage example
Query
Response
JSONDynamicPaths
Introduced in: v24.8.0 Returns the list of dynamic paths that are stored as separate subcolumns in JSON column. Syntaxjson— JSON column.JSON
Array(String)
Examples
Usage example
Query
Response
JSONDynamicPathsWithTypes
Introduced in: v24.8.0 Returns the list of dynamic paths that are stored as separate subcolumns and their types in each row in JSON column. Syntaxjson— JSON column.JSON
Map(String, String)
Examples
Usage example
Query
Response
JSONExtract
Introduced in: v19.14.0 Parses JSON and extracts a value with given ClickHouse data type. Syntaxjson— JSON string to parse.Stringindices_or_keys— A list of zero or more arguments each of which can be either string or integer.Stringor(U)Int*return_type— ClickHouse data type to return.String
Query
Response
JSONExtractArrayRaw
Introduced in: v20.1.0 Returns an array with elements of JSON array, each represented as unparsed string. Syntaxjson— JSON string to parse.Stringindices_or_keys— A list of zero or more arguments each of which can be either string or integer.Stringor(U)Int*
Array(String)
Examples
Usage example
Query
Response
JSONExtractArrayRawCaseInsensitive
Introduced in: v25.8.0 Returns an array with elements of JSON array, each represented as unparsed string, using case-insensitive key matching. This function is similar toJSONExtractArrayRaw.
Syntax
json— JSON string to parseStringindices_or_keys— Optional. Indices or keys to navigate to the array. Keys use case-insensitive matchingStringor(U)Int*
Array(String)
Examples
basic
Query
Response
JSONExtractBool
Introduced in: v20.1.0 Parses JSON and extracts a value of Bool type. Syntaxjson— JSON string to parse.Stringindices_or_keys— A list of zero or more arguments each of which can be either string or integer.Stringor(U)Int*
0. Bool
Examples
Usage example
Query
Response
JSONExtractBoolCaseInsensitive
Introduced in: v25.8.0 Parses JSON and extracts a boolean value using case-insensitive key matching. This function is similar toJSONExtractBool.
Syntax
json— JSON string to parseStringindices_or_keys— Optional. Indices or keys to navigate to the field. Keys use case-insensitive matchingStringor(U)Int*
UInt8
Examples
basic
Query
Response
JSONExtractCaseInsensitive
Introduced in: v25.8.0 Parses JSON and extracts a value of the given ClickHouse data type using case-insensitive key matching. This function is similar toJSONExtract.
Syntax
json— JSON string to parseStringindices_or_keys— Optional. Indices or keys to navigate to the field. Keys use case-insensitive matchingStringor(U)Int*return_type— The ClickHouse data type to extractString
Any
Examples
int_type
Query
Response
Query
Response
JSONExtractFloat
Introduced in: v20.1.0 Parses JSON and extracts a value of Float type. Syntaxjson— JSON string to parse.Stringindices_or_keys— A list of zero or more arguments each of which can be either string or integer.Stringor(U)Int*
0. Float64
Examples
Usage example
Query
Response
JSONExtractFloatCaseInsensitive
Introduced in: v25.8.0 Parses JSON and extracts a value of Float type using case-insensitive key matching. This function is similar toJSONExtractFloat.
Syntax
json— JSON string to parseStringindices_or_keys— Optional. Indices or keys to navigate to the field. Keys use case-insensitive matchingStringor(U)Int*
Float64
Examples
basic
Query
Response
JSONExtractInt
Introduced in: v20.1.0 Parses JSON and extracts a value of Int type. Syntaxjson— JSON string to parse.Stringindices_or_keys— A list of zero or more arguments each of which can be either string or integer.Stringor(U)Int*
0. Int64
Examples
Usage example
Query
Response
JSONExtractIntCaseInsensitive
Introduced in: v25.8.0 Parses JSON and extracts a value of Int type using case-insensitive key matching. This function is similar toJSONExtractInt.
Syntax
json— JSON string to parseStringindices_or_keys— Optional. Indices or keys to navigate to the field. Keys use case-insensitive matchingStringor(U)Int*
Int64
Examples
basic
Query
Response
Query
Response
JSONExtractKeys
Introduced in: v21.11.0 Parses a JSON string and extracts the keys. Syntaxjson— JSON string to parse.Stringindices_or_keys— A list of zero or more arguments each of which can be either string or integer.Stringor(U)Int*
Array(String)
Examples
Usage example
Query
Response
JSONExtractKeysAndValues
Introduced in: v20.1.0 Parses key-value pairs from a JSON where the values are of the given ClickHouse data type. Syntaxjson— JSON string to parse.Stringindices_or_keys— A list of zero or more arguments each of which can be either string or integer.Stringor(U)Int*value_type— ClickHouse data type of the values.String
Array(Tuple(String, value_type))
Examples
Usage example
Query
Response
JSONExtractKeysAndValuesCaseInsensitive
Introduced in: v25.8.0 Parses key-value pairs from JSON using case-insensitive key matching. This function is similar toJSONExtractKeysAndValues.
Syntax
json— JSON string to parseStringindices_or_keys— Optional. Indices or keys to navigate to the object. Keys use case-insensitive matchingStringor(U)Int*value_type— The ClickHouse data type of the valuesString
Array(Tuple(String, T))
Examples
basic
Query
Response
JSONExtractKeysAndValuesRaw
Introduced in: v20.4.0 Returns an array of tuples with keys and values from a JSON object. All values are represented as unparsed strings. Syntaxjson— JSON string to parse.Stringindices_or_keys— A list of zero or more arguments each of which can be either string or integer.Stringor(U)Int*
Array(Tuple(String, String))
Examples
Usage example
Query
Response
JSONExtractKeysAndValuesRawCaseInsensitive
Introduced in: v25.8.0 Extracts raw key-value pairs from JSON using case-insensitive key matching. This function is similar toJSONExtractKeysAndValuesRaw.
Syntax
json— JSON string to parseStringindices_or_keys— Optional. Indices or keys to navigate to the object. Keys use case-insensitive matchingStringor(U)Int*
Array(Tuple(String, String))
Examples
basic
Query
Response
JSONExtractKeysCaseInsensitive
Introduced in: v25.8.0 Parses a JSON string and extracts the keys using case-insensitive key matching to navigate to nested objects. This function is similar toJSONExtractKeys.
Syntax
json— JSON string to parseStringindices_or_keys— Optional. Indices or keys to navigate to the object. Keys use case-insensitive matchingStringor(U)Int*
Array(String)
Examples
basic
Query
Response
Query
Response
JSONExtractRaw
Introduced in: v20.1.0 Returns a part of JSON as unparsed string. Syntaxjson— JSON string to parse.Stringindices_or_keys— A list of zero or more arguments each of which can be either string or integer.Stringor(U)Int*
String
Examples
Usage example
Query
Response
JSONExtractRawCaseInsensitive
Introduced in: v25.8.0 Returns part of the JSON as an unparsed string using case-insensitive key matching. This function is similar toJSONExtractRaw.
Syntax
json— JSON string to parseStringindices_or_keys— Optional. Indices or keys to navigate to the field. Keys use case-insensitive matchingStringor(U)Int*
String
Examples
object
Query
Response
JSONExtractString
Introduced in: v20.1.0 Parses JSON and extracts a value of String type. Syntaxjson— JSON string to parse.Stringindices_or_keys— A list of zero or more arguments each of which can be either string or integer.Stringor(U)Int*
String
Examples
Usage example
Query
Response
JSONExtractStringCaseInsensitive
Introduced in: v25.8.0 Parses JSON and extracts a string using case-insensitive key matching. This function is similar toJSONExtractString.
Syntax
json— JSON string to parseStringindices_or_keys— Optional. Indices or keys to navigate to the field. Keys use case-insensitive matchingStringor(U)Int*
String
Examples
basic
Query
Response
Query
Response
JSONExtractUInt
Introduced in: v20.1.0 Parses JSON and extracts a value of UInt type. Syntaxjson— JSON string to parse.Stringindices_or_keys— A list of zero or more arguments each of which can be either string or integer.Stringor(U)Int*
0. UInt64
Examples
Usage example
Query
Response
JSONExtractUIntCaseInsensitive
Introduced in: v25.8.0 Parses JSON and extracts a value of UInt type using case-insensitive key matching. This function is similar toJSONExtractUInt.
Syntax
json— JSON string to parseStringindices_or_keys— Optional. Indices or keys to navigate to the field. Keys use case-insensitive matchingStringor(U)Int*
UInt64
Examples
basic
Query
Response
JSONHas
Introduced in: v20.1.0 Checks for the existence of the provided value(s) in the JSON document. Syntaxjson— JSON string to parseString[ ,indices_or_keys, ...]— A list of zero or more arguments.Stringor(U)Int*
1 if the value exists in json, otherwise 0 UInt8
Examples
Usage example
Query
Response
JSONKey
Introduced in: v20.1.0 Returns the key of a JSON object field by its index (1-based). If the JSON is passed as a string, it is parsed first. The second argument is a JSON path to navigate into nested objects. The function returns the key name at the specified position. Syntaxjson— JSON string to parse.Stringindices_or_keys— Optional list of indices or keys specifying a path to a nested element. Each argument can be either a string (access by key) or an integer (access by index starting from 1).StringorInt*
String
Examples
Usage example
Query
Response
JSONLength
Introduced in: v20.1.0 Return the length of a JSON array or a JSON object. If the value does not exist or has the wrong type,0 will be returned.
Syntax
json— JSON string to parseString[, indices_or_keys, ...]— Optional. A list of zero or more arguments.Stringor(U)Int8/16/32/64
0 if the value does not exist or has the wrong type. UInt64
Examples
Usage example
Query
Response
JSONMergePatch
Introduced in: v23.10.0 Returns the merged JSON object string which is formed by merging multiple JSON objects. SyntaxjsonMergePatch
Arguments
json1[, json2, ...]— One or more strings with valid JSON.String
String
Examples
Usage example
Query
Response
JSONSharedDataPaths
Introduced in: v24.8.0 Returns the list of paths that are stored in shared data structure in JSON column. Syntaxjson— JSON column.JSON
Array(String)
Examples
Usage example
Query
Response
JSONSharedDataPathsWithTypes
Introduced in: v24.8.0 Returns the list of paths that are stored in shared data structure and their types in each row in JSON column. Syntaxjson— JSON column.JSON
Map(String, String)
Examples
Usage example
Query
Response
JSONType
Introduced in: v20.1.0 Return the type of a JSON value. If the value does not exist,Null=0 will be returned.
Syntax
json— JSON string to parseStringjson[, indices_or_keys, ...]— A list of zero or more arguments, each of which can be either string or integer.Stringor(U)Int8/16/32/64
Null=0 Enum
Examples
Usage example
Query
Response
JSON_EXISTS
Introduced in: v21.8.0 If the value exists in the JSON document,1 will be returned.
If the value does not exist, 0 will be returned.
Syntax
1 if the value exists in the JSON document, otherwise 0. UInt8
Examples
Usage example
Query
Response
JSON_QUERY
Introduced in: v21.8.0 Parses a JSON and extract a value as a JSON array or JSON object. If the value does not exist, an empty string will be returned. SyntaxString
Examples
Usage example
Query
Response
JSON_VALUE
Introduced in: v21.11.0 Parses a JSON and extract a value as a JSON scalar. If the value does not exist, an empty string will be returned by default. This function is controlled by the following settings:- by SET
function_json_value_return_type_allow_nullable=true,NULLwill be returned. If the value is complex type (such as: struct, array, map), an empty string will be returned by default. - by SET
function_json_value_return_type_allow_complex=true, the complex value will be returned.
String
Examples
Usage example
Query
Response
dynamicElement
Introduced in: v24.1.0 Extracts a column with specified type from aDynamic column.
This function allows you to extract values of a specific type from a Dynamic column. If a row contains a value
of the requested type, it returns that value. If the row contains a different type or NULL, it returns NULL
for scalar types or an empty array for array types.
Syntax
dynamic— Dynamic column to extract from.Dynamictype_name— The name of the variant type to extract (e.g., ‘String’, ‘Int64’, ‘Array(Int64)’).
Any
Examples
Extracting different types from Dynamic column
Query
Response
dynamicType
Introduced in: v24.1.0 Returns the variant type name for each row of aDynamic column.
For rows containing NULL, the function returns ‘None’. For all other rows, it returns the actual data type
stored in that row of the Dynamic column (e.g., ‘Int64’, ‘String’, ‘Array(Int64)’).
Syntax
dynamic— Dynamic column to inspect.Dynamic
String
Examples
Inspecting types in Dynamic column
Query
Response
isDynamicElementInSharedData
Introduced in: v24.1.0 Returns true for rows in a Dynamic column that are stored in shared variant format rather than as separate subcolumns. When a Dynamic column has amax_types limit, values that exceed this limit are stored in a shared binary format
instead of being separated into individual typed subcolumns. This function identifies which rows are stored in this shared format.
Syntax
dynamic— Dynamic column to inspect.Dynamic
Bool
Examples
Checking storage format in Dynamic column with max_types limit
Query
Response
isValidJSON
Introduced in: v20.1.0 Checks that the string passed is valid JSON. Syntaxjson— JSON string to validateString
1 if the string is valid JSON, otherwise 0. UInt8
Examples
Usage example
Query
Response
Query
Response
simpleJSONExtractBool
Introduced in: v21.4.0 Parses a true/false value from the value of the field namedfield_name.
The result is UInt8.
Syntax
visitParamExtractBool
Arguments
json— The JSON in which the field is searched for.Stringfield_name— The name of the field to search for.const String
1 if the value of the field is true, 0 otherwise. This means this function will return 0 including (and not only) in the following cases:
- If the field doesn’t exists.
- If the field contains
trueas a string, e.g.:{"field":"true"}. - If the field contains
1as a numerical value.UInt8
Query
Response
simpleJSONExtractFloat
Introduced in: v21.4.0 ParsesFloat64 from the value of the field named field_name.
If field_name is a string field, it tries to parse a number from the beginning of the string.
If the field does not exist, or it exists but does not contain a number, it returns 0.
Syntax
visitParamExtractFloat
Arguments
json— The JSON in which the field is searched for.Stringfield_name— The name of the field to search for.const String
0. Float64
Examples
Usage example
Query
Response
simpleJSONExtractInt
Introduced in: v21.4.0 ParsesInt64 from the value of the field named field_name.
If field_name is a string field, it tries to parse a number from the beginning of the string.
If the field does not exist, or it exists but does not contain a number, it returns 0.
Syntax
visitParamExtractInt
Arguments
json— The JSON in which the field is searched for.Stringfield_name— The name of the field to search for.const String
0 otherwise Int64
Examples
Usage example
Query
Response
simpleJSONExtractRaw
Introduced in: v21.4.0 Returns the value of the field namedfield_name as a String, including separators.
Syntax
visitParamExtractRaw
Arguments
json— The JSON in which the field is searched for.Stringfield_name— The name of the field to search for.const String
String
Examples
Usage example
Query
Response
simpleJSONExtractString
Introduced in: v21.4.0 ParsesString in double quotes from the value of the field named field_name.
Implementation details
There is currently no support for code points in the format \uXXXX\uYYYY that are not from the basic multilingual plane (they are converted to CESU-8 instead of UTF-8).
Syntax
visitParamExtractString
Arguments
json— The JSON in which the field is searched for.Stringfield_name— The name of the field to search for.const String
String
Examples
Usage example
Query
Response
simpleJSONExtractUInt
Introduced in: v21.4.0 ParsesUInt64 from the value of the field named field_name.
If field_name is a string field, it tries to parse a number from the beginning of the string.
If the field does not exist, or it exists but does not contain a number, it returns 0.
Syntax
visitParamExtractUInt
Arguments
json— The JSON in which the field is searched for.Stringfield_name— The name of the field to search for.const String
0 otherwise UInt64
Examples
Usage example
Query
Response
simpleJSONHas
Introduced in: v21.4.0 Checks whether there is a field namedfield_name.
Syntax
visitParamHas
Arguments
json— The JSON in which the field is searched for.Stringfield_name— The name of the field to search for.const String
1 if the field exists, 0 otherwise UInt8
Examples
Usage example
Query
Response
toJSONString
Introduced in: v21.7.0 Serializes a value to its JSON representation. Various data types and nested structures are supported. 64-bit integers or bigger (likeUInt64 or Int128) are enclosed in quotes by default. output_format_json_quote_64bit_integers controls this behavior.
Special values NaN and inf are replaced with null. Enable output_format_json_quote_denormals setting to show them.
When serializing an Enum value, the function outputs its name.
See also:
Syntax
value— Value to serialize. Value may be of any data type.Any
String
Examples
Map serialization
Query
Response
Query
Response