blob: 24bbd95d533615c1c5a91cad963725a23c182afd [file] [log] [blame] [view]
---
{
"title": "JSON_VALID",
"language": "en"
}
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
## json_valid
### description
json_valid functions returns 0 or 1 to indicate whether a value is valid JSON and Returns NULL if the argument is NULL.
#### Syntax
`JSONB json_valid(VARCHAR json_str)`
### example
1. parse valid JSON string
```
MySQL > SELECT json_valid('{"k1":"v31","k2":300}');
+-------------------------------------+
| json_valid('{"k1":"v31","k2":300}') |
+-------------------------------------+
| 1 |
+-------------------------------------+
1 row in set (0.02 sec)
```
2. parse invalid JSON string
```
MySQL > SELECT json_valid('invalid json');
+----------------------------+
| json_valid('invalid json') |
+----------------------------+
| 0 |
+----------------------------+
1 row in set (0.02 sec)
```
3. parse NULL
```
MySQL > select json_valid(NULL);
+------------------+
| json_valid(NULL) |
+------------------+
| NULL |
+------------------+
1 row in set (0.02 sec)
```
### keywords
JSON, VALID, JSON_VALID