SQLite 3 reference · JSON Functions

SQLite JSON_VALID() Function

Return 1 if a string is well-formed JSON and 0 if it isn't. Use it in CHECK constraints or before parsing.

SQLite 3 Since 3.9.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

json_valid(X, flags)

Parameters

ParameterDescription
X The text to check.
flags optional What counts as valid (JSON5, JSONB); 1 = strict JSON.

Return value

1 or 0.

Examples

Valid or notTry it yourself
SELECT json_valid('{"a":1}') AS a, json_valid('[1,2,') AS b, json_valid('"text"') AS c;

Output

a | b | c
1 | 0 | 1
A CHECK constraintTry it yourself
CREATE TABLE settings (data TEXT CHECK (json_valid(data)));
INSERT INTO settings VALUES ('{"theme":"dark"}');
SELECT data ->> 'theme' AS theme FROM settings;

Output

theme
dark

Version history

VersionChange
SQLite 3.9.0Added
SQLite 3.38.0Built in by default; earlier versions needed the JSON1 extension.

Was this page helpful?