Returns NULL if the input string is a valid JSON document or NULL.
Otherwise, returns an error message.
Syntax
CHECK_JSON(<json_string>)
Parameters
| Parameter | Description | Supported input types |
|---|
<json_string> | The string to validate as JSON. | TEXT |
Return Type
The CHECK_JSON function returns a result of type TEXT.
If you don’t care about the error message, you can also use the JSON_IS_VALID function.
Examples
Example
The following code example validates a simple JSON string. Returns NULL because the input string is valid JSON.
SELECT CHECK_JSON('{"name": "John"}');
Rows: 1Execution time: 5.15ms
Example
The following code example validates a simple JSON string. Returns an error message because the input string is invalid JSON as it contains two JSON objects next to each other.
SELECT CHECK_JSON('{"name": "John"}{"name": "John"}');
| check_json text null |
|---|
| TAPE_ERROR: The JSON document has an improper structure: missing or superfluous commas, braces, missing keys, etc. |
Rows: 1Execution time: 4.89ms