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