JSON_PARSE_NOTNULL_ERROR_TO_VALUE
Descriptionβ
Function to parse JSON strings. If the JSON string format is invalid or a parsing error occurs, the function returns the default value specified by the user instead of returning an invalid JSON object. The main purpose of this function is to provide a default value that can be used to replace invalid results in case of parsing errors, ensuring that the query returns a reasonable value.
Syntaxβ
JSON_PARSE_NOTNULL_ERROR_TO_VALUE(< str >, <default_value>)
Aliasβ
- JSONB_PARSE_NOTNULL_ERROR_TO_VALUE
Required Parametersβ
parameters | described |
---|---|
<str> | The JSON string to parse. This parameter should be a valid JSON string. If the JSON format is invalid, the function returns default_value. |
<default_value> | The default value returned when parsing the error. This parameter can be of any type and is used to replace invalid JSON-formatted data. |
Return Valueβ
Return a JSON object. If the input JSON string is valid, the parsed JSON object is returned. If invalid, return the user-specified default_value.
Examplesβ
SELECT JSON_PARSE_NOTNULL_ERROR_TO_VALUE('{"name": "Alice", "age": 30}', '{"name": "Unknown", "age": 0}') AS parsed_json;
+-------------------------------------------+
| parsed_json |
+-------------------------------------------+
| {"name":"Alice","age":30} |
+-------------------------------------------+