📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

JSON Functions



This section provides reference information for JSON functions in TiDB Cloud Lake. JSON functions enable parsing, validation, querying, and manipulation of JSON data structures.

JSON Parsing & Validation

FunctionDescriptionExample
PARSE_JSONParses a JSON string into a variant valuePARSE_JSON('{"name":"John","age":30}') → {"name":"John","age":30}
CHECK_JSONValidates if a string is valid JSONCHECK_JSON('{"valid": true}') → true

JSON Type Information

FunctionDescriptionExample
JSON_TYPEOFReturns the type of a JSON valueJSON_TYPEOF('{"key": "value"}') → 'OBJECT'

JSON Conversion

FunctionDescriptionExample
JSON_TO_STRINGConverts a JSON value to a stringJSON_TO_STRING({"name":"John"}) → '{"name":"John"}'

JSON Path Operations

FunctionDescriptionExample
JSON_PATH_EXISTSChecks if a JSON path existsJSON_PATH_EXISTS('{"a":1}', '$.a') → true
JSON_PATH_MATCHMatches JSON values against a path patternJSON_PATH_MATCH('{"items":[1,2,3]}', '$.items[*]') → [1,2,3]
JSON_PATH_QUERYQueries JSON data using JSONPathJSON_PATH_QUERY('{"a":1,"b":2}', '$.a') → 1
JSON_PATH_QUERY_ARRAYQueries JSON data and returns results as an arrayJSON_PATH_QUERY_ARRAY('[1,2,3]', '$[*]') → [1,2,3]
JSON_PATH_QUERY_FIRSTReturns the first result from a JSON path queryJSON_PATH_QUERY_FIRST('[1,2,3]', '$[*]') → 1

JSON Data Extraction

FunctionDescriptionExample
GETExtracts value from JSON by index or field nameGET('{"name":"John"}', 'name') → "John"
GET_IGNORE_CASEExtracts value with case-insensitive field matchingGET_IGNORE_CASE('{"Name":"John"}', 'name') → "John"
GET_BY_KEYPATHExtracts nested value using brace key pathsGET_BY_KEYPATH('{"user":{"name":"Ada"}}', '{user,name}') → "Ada"
GET_PATHExtracts value using path notationGET_PATH('{"user":{"name":"John"}}', 'user.name') → "John"
JSON_EXTRACT_PATH_TEXTExtracts text value from JSON using pathJSON_EXTRACT_PATH_TEXT('{"name":"John"}', 'name') → 'John'
JSON_EACHExpands JSON object into key-value pairsJSON_EACH('{"a":1,"b":2}') → [("a",1),("b",2)]
JSON_ARRAY_ELEMENTSExpands JSON array into individual elementsJSON_ARRAY_ELEMENTS('[1,2,3]') → 1, 2, 3
JQProcesses JSON using jq-style queriesJQ('{"name":"John"}', '.name') → "John"

JSON Formatting & Processing

FunctionDescriptionExample
JSON_PRETTYFormats JSON with proper indentationJSON_PRETTY('{"a":1}') → Formatted JSON string
STRIP_NULL_VALUERemoves null values from JSONSTRIP_NULL_VALUE('{"a":1,"b":null}') → {"a":1}
JSON_STRIP_NULLSRemoves null values from JSON ObjectJSON_STRIP_NULLS(PARSE_JSON('{"a":1,"b":null}')) → {"a":1}

JSON Containment & Existence

FunctionDescriptionExample
JSON_CONTAINS_IN_LEFTTests whether the left JSON contains the right JSONJSON_CONTAINS_IN_LEFT('{"a":1,"b":2}', '{"b":2}') → true
JSON_EXISTS_KEYChecks whether specific keys existJSON_EXISTS_KEY('{"a":1}', 'a') → true
JSON_EXISTS_ANY_KEYSReturns true if any key in the list existsJSON_EXISTS_ANY_KEYS('{"a":1}', ['x','a']) → true
JSON_EXISTS_ALL_KEYSReturns true only if all keys existJSON_EXISTS_ALL_KEYS('{"a":1,"b":2}', ['a','b']) → true

Was this page helpful?