MySQL JSON_VALID() Function
In MySQL, the JSON_VALID()
function returns 0 and 1 to indicate whether the given parameter is a valid JSON document.
JSON_VALID()
Syntax
Here is the syntax of the MySQL JSON_VALID()
function:
JSON_VALID(str)
Parameters
str
- Required. Content that needs to be verified.
Return value
The JSON_VALID()
function verifies whether the given parameter is a valid JSON document. If the given parameter is a valid JSON document, the JSON_VALID()
function returns 1
; Otherwise returns 0
.
This function will return NULL
if the parameter is NULL
.
JSON_VALID()
Examples
Here are some examples of JSON_VALID()
.
Example 1
SELECT JSON_VALID(1), JSON_VALID('1');
+---------------+-----------------+
| JSON_VALID(1) | JSON_VALID('1') |
+---------------+-----------------+
| 0 | 1 |
+---------------+-----------------+
Example 2
SELECT JSON_VALID(true), JSON_VALID('true');
+------------------+--------------------+
| JSON_VALID(true) | JSON_VALID('true') |
+------------------+--------------------+
| 0 | 1 |
+------------------+--------------------+
Example 3
SELECT JSON_VALID('abc'), JSON_VALID('"abc"');
+-------------------+---------------------+
| JSON_VALID('abc') | JSON_VALID('"abc"') |
+-------------------+---------------------+
| 0 | 1 |
+-------------------+---------------------+
Example 4
SELECT JSON_VALID('{"a": 1}'), JSON_VALID('{a: 1}');
+------------------------+----------------------+
| JSON_VALID('{"a": 1}') | JSON_VALID('{a: 1}') |
+------------------------+----------------------+
| 1 | 0 |
+------------------------+----------------------+