JSON_PARSE_NULLABLE_ERROR_TO_INVALID
Descriptionβ
The JSON_PARSE_NULLABLE_ERROR_TO_INVALID
function is used to parse a JSON string into a valid JSON object. If the input JSON string is invalid, it will return an "invalid JSON" marker (typically INVALID_JSON
), without throwing an error. If the input is NULL
, it will also return the INVALID_JSON
marker.
Syntaxβ
JSON_PARSE_NULLABLE_ERROR_TO_INVALID( <str> )
Aliasβ
- JSONB_PARSE_NULLABLE_ERROR_TO_INVALID
Required Parametersβ
Parameter | Description |
---|---|
<str> | The input string in JSON format to be parsed. |
Return Valueβ
Condition | 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 the INVALID_JSON marker. |
Examplesβ
- Valid JSON string:
SELECT JSON_PARSE_NULLABLE_ERROR_TO_INVALID('{"name": "John", "age": 30}');
+----------------------------------------------------------------------+
| JSON_PARSE_NULLABLE_ERROR_TO_INVALID('{"name": "John", "age": 30}') |
+----------------------------------------------------------------------+
| {"name": "John", "age": 30} |
+----------------------------------------------------------------------+
- Invalid JSON string:
SELECT JSON_PARSE_NULLABLE_ERROR_TO_INVALID('{"name": "John", "age": }');
+-------------------------------------------------------------------+
| JSON_PARSE_NULLABLE_ERROR_TO_INVALID('{"name": "John", "age": }') |
+-------------------------------------------------------------------+
| INVALID_JSON |
+-------------------------------------------------------------------+
- Input is NULL:
SELECT JSON_PARSE_NULLABLE_ERROR_TO_INVALID(NULL);
+---------------------------------------------------------------+
| JSON_PARSE_NULLABLE_ERROR_TO_INVALID(NULL) |
+---------------------------------------------------------------+
| INVALID_JSON |
+---------------------------------------------------------------+