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
Syntax
json_valid(X, flags)
Parameters
| Parameter | Description |
|---|---|
X |
The text to check. |
flags optional |
What counts as valid (JSON5, JSONB); 1 = strict JSON. |
Return value
1 or 0.
Examples
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
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
| Version | Change |
|---|---|
| SQLite 3.9.0 | Added |
| SQLite 3.38.0 | Built in by default; earlier versions needed the JSON1 extension. |
Related
JSON()· Check and minify JSON text: return it without extra whitespace, or raise an error if it isn't valid JSON.JSON_TYPE()· Return the JSON type of a value or path: 'null', 'true', 'false', 'integer', 'real', 'text', 'array' or 'object'.- SQL String Functions · tutorial