VeloDB Cloud
SQL Reference
SQL Functions
Scalar Functions
Json Functions
JSON_PARSE_NULLABLE_ERROR_TO_NULL

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

ParameterDescription
<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

  1. 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}                                    |
+---------------------------------------------------------------+
 
  1. Invalid JSON string:
SELECT JSON_PARSE_NULLABLE_ERROR_TO_NULL('{"name": "John", "age": }');
 
+---------------------------------------------------------------+
| JSON_PARSE_NULLABLE_ERROR_TO_NULL('{"name": "John", "age": }') |
+---------------------------------------------------------------+
| NULL                                                          |
+---------------------------------------------------------------+
 
  1. Input is NULL:
SELECT JSON_PARSE_NULLABLE_ERROR_TO_NULL(NULL);
 
+---------------------------------------------------------------+
| JSON_PARSE_NULLABLE_ERROR_TO_NULL(NULL)                        |
+---------------------------------------------------------------+
| NULL                                                          |
+---------------------------------------------------------------+