VeloDB Cloud
SQL Reference
SQL Functions
Scalar Functions
Json Functions
JSON_PARSE_NULLABLE_ERROR_TO_INVALID

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

ParameterDescription
<str>The input string in JSON format to be parsed.

Return Value

ConditionReturn Value
If the input string is a valid JSONIt returns the corresponding JSON object.
If the input string is invalid or NULLIt returns the INVALID_JSON marker.

Examples

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