MariaDB JSON_VALID() Function
In MariaDB, JSON_VALID() is a built-in function that returns 0 and 1 to indicate whether the given argument is a valid JSON document.
MariaDB JSON_VALID() Syntax
Here is the syntax for the MariaDB JSON_VALID() function:
JSON_VALID(str)
Parameters
str- 
Required. Content that needs to be verified.
 
If you supply the wrong number of arguments, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'JSON_VALID'.
Return value
The MariaDB JSON_VALID() function verifies that the given parameter is a valid JSON document. If the given argument is a valid JSON document, the JSON_VALID() function returns 1, if not a JSON document, the JSON_VALID() function returns 0.
If the argument is NULL, the JSON_VALID() function will return NULL.
MariaDB JSON_VALID() Examples
Here are some common examples to show the usages of the Mariadb JSON_VALID() function.
Numbers
SELECT JSON_VALID(1), JSON_VALID('1');
Output:
+---------------+-----------------+
| JSON_VALID(1) | JSON_VALID('1') |
+---------------+-----------------+
|             1 |               1 |
+---------------+-----------------+Boolean values
SELECT JSON_VALID(true), JSON_VALID('true');
Output:
+------------------+--------------------+
| JSON_VALID(true) | JSON_VALID('true') |
+------------------+--------------------+
|                1 |                  1 |
+------------------+--------------------+Strings
SELECT JSON_VALID('abc'), JSON_VALID('"abc"');
Output:
+-------------------+---------------------+
| JSON_VALID('abc') | JSON_VALID('"abc"') |
+-------------------+---------------------+
|                 0 |                   1 |
+-------------------+---------------------+Arrays
SELECT JSON_VALID('[1,2,3]'), JSON_VALID('[1,2,a]');
Output:
+-----------------------+-----------------------+
| JSON_VALID('[1,2,3]') | JSON_VALID('[1,2,a]') |
+-----------------------+-----------------------+
|                     1 |                     0 |
+-----------------------+-----------------------+Objects
SELECT JSON_VALID('{"a": 1}'), JSON_VALID('{a: 1}');
Output:
+------------------------+----------------------+
| JSON_VALID('{"a": 1}') | JSON_VALID('{a: 1}') |
+------------------------+----------------------+
|                      1 |                    0 |
+------------------------+----------------------+NULL parameter
The MariaDB JSON_VALID() function will return NULL if the argument is NULL.
SELECT JSON_VALID(NULL);
Output:
+------------------+
| JSON_VALID(NULL) |
+------------------+
|             NULL |
+------------------+Conclusion
In MariaDB, JSON_VALID() is a built-in function that returns 0 and 1 to indicate whether the given argument is a valid JSON document.