SQLite json_valid() Function

The SQLite json_valid() function returns 0 or 1 to indicate whether the given parameter is a valid JSON document.

Syntax

Here is the syntax of the SQLite json_valid() function:

json_valid(str)

Parameters

str

Required. The text 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 can be converted into a valid JSON document, the json_valid() function returns 1; otherwise, the json_valid() function returns 0.

This function will return NULL if the parameter is NULL.

Examples

Here are some examples to show the usages of json_valid().

Example 1

SELECT
    json_valid(1),
    json_valid('1');
  json_valid(1) = 1
json_valid('1') = 1

Example 2

SELECT
    json_valid(true),
    json_valid('true');
  json_valid(true) = 1
json_valid('true') = 1

Example 3

SELECT
    json_valid('abc'),
    json_valid('"abc"');
  json_valid('abc') = 0
json_valid('"abc"') = 1

Example 4

SELECT
    json_valid('{"a": 1}'),
    json_valid('{a: 1}');
json_valid('{"a": 1}') = 1
  json_valid('{a: 1}') = 0