json_parse_nullable_error_to_null
Descriptionβ
The JSON_PARSE_NULLABLE_ERROR_TO_NULL
function is used to parse a JSON string into a valid JSON object. If the input JSON string is invalid, it will return NULL
without throwing an error. If the input is NULL
, it will directly return NULL
.
Syntaxβ
JSON_PARSE_NULLABLE_ERROR_TO_NULL( <str> )
Aliasesβ
- JSONB_PARSE_NULLABLE_ERROR_TO_NULL
Required Parametersβ
Parameter | Description |
---|---|
<str> | The input string in JSON format to be parsed. |
Return Valueβ
If the input string is a valid JSON, it returns the corresponding JSON object. If the input string is invalid or NULL, it returns NULL.
Examplesβ
- Valid JSON string:
SELECT JSON_PARSE_NULLABLE_ERROR_TO_NULL('{"name": "John", "age": 30}');
+---------------------------------------------------------------+
| JSON_PARSE_NULLABLE_ERROR_TO_NULL('{"name": "John", "age": 30}') |
+---------------------------------------------------------------+
| {"name": "John", "age": 30} |
+---------------------------------------------------------------+
- Invalid JSON string:
SELECT JSON_PARSE_NULLABLE_ERROR_TO_NULL('{"name": "John", "age": }');
+---------------------------------------------------------------+
| JSON_PARSE_NULLABLE_ERROR_TO_NULL('{"name": "John", "age": }') |
+---------------------------------------------------------------+
| NULL |
+---------------------------------------------------------------+
- Input is NULL:
SELECT JSON_PARSE_NULLABLE_ERROR_TO_NULL(NULL);
+---------------------------------------------------------------+
| JSON_PARSE_NULLABLE_ERROR_TO_NULL(NULL) |
+---------------------------------------------------------------+
| NULL |
+---------------------------------------------------------------+