JSON_VALID()

Overview

Returns a boolean value to indicate if a string is valid JSON data.

USAGE

JSON_VALID(json_data)

Argument Name

Description

json_data

The JSON data to check

DETAILS

JSON_VALID() is a JSON function that validates the syntax of JSON data.

JSON data is valid if it conforms to ECMA-404: The JSON Data Interchange Standard.

If the argument is valid JSON data a 1 is returned; if it is invalid JSON data, a 0 is returned; if it is a NULL, NULL is returned.

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

EXAMPLES

With Literal Values

In the following example, JSON_VALID() is called with literal values:

SELECT JSON_VALID('{"bar": "a string"}') AS out_1,
       JSON_VALID('[a,1]') AS out_2,
       JSON_VALID(5) AS out_3;
+-------+-------+-------+
| out_1 | out_2 | out_3 |
+-------+-------+-------+
|     1 |     0 |     1 |
+-------+-------+-------+

Example Schema and Data

Some of the examples are based on the contacts table. We are using a TEXT field instead of a JSON field so that we can insert invalid data:

CREATE TABLE valid_test (
  example TEXT
);
INSERT INTO valid_test VALUES
  ('{"foo": 42, "bar": "hi"}'),
  ('{4: 5}'),
  (NULL);

Per-row Values

SELECT JSON_VALID(example) AS is_valid
FROM valid_test;
+----------+
| is_valid |
+----------+
|        1 |
|        0 |
|     NULL |
+----------+

ERROR HANDLING

FEATURE INTERACTION

RESPONSES

DIAGNOSIS

ISO 9075:2016

CHANGE HISTORY

Release Series

History

23.09

  • Present starting in MariaDB Xpand 23.09.1.

6.1

  • Present starting in MariaDB Xpand 6.1.0.

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.1

  • Present starting in MariaDB Xpand 6.1.0.

EXTERNAL REFERENCES