// strings reference

SQL JSON_VALID function

JSON_VALID(raw) = 1 says the text parses as JSON. Checking at load time turns a query-time error into a rejected row.

Kategorie
Strings
Returns
integer or boolean
In this category
142 of 172

Syntax

JSON_VALID(str)  -- MySQL, SQLite
ISJSON(str)  -- SQL Server
str IS JSON  -- Oracle

Each block is a separate form. The support table and the examples show which engine takes which.

Engine-Unterstützung

EngineSupportNotizen
SQL Server Ja Supported under this name.
PostgreSQL Ja the IS JSON predicate, PostgreSQL 16+
MySQL Ja Supported under this name.
SQLite Ja Supported under this name.
Oracle Ja the IS JSON condition, 12c+

Beispiele

MySQL

SELECT JSON_VALID('{"a": 1}') AS ok,
       JSON_VALID('{a: 1}') AS not_ok;

SQL Server

SELECT * FROM staging
WHERE ISJSON(raw) = 1;

SQLite

SELECT * FROM imports WHERE json_valid(raw);

Gut zu wissen

  • MySQL, SQLite and SQL Server's ISJSON return 1 or 0; Oracle's and PostgreSQL's IS JSON is a predicate used directly in WHERE and CHECK.
  • Oracle's IS JSON is lax by default and accepts {a: 1} with an unquoted key; write IS JSON STRICT for RFC 8259. SQLite's json_valid(x) is strict, while json_valid(x, 6) accepts JSON5.
  • PostgreSQL's json and jsonb types reject invalid input on insert, so IS JSON is for text columns. It also tests shape: raw IS JSON OBJECT, IS JSON ARRAY, IS JSON SCALAR.

Questions about JSON_VALID / ISJSON

Can a CHECK constraint enforce JSON?

Yes: CHECK (raw IS JSON) on Oracle and PostgreSQL 16+, CHECK (ISJSON(raw) = 1) on SQL Server, CHECK (json_valid(raw)) on SQLite. On MySQL, a native JSON column validates by itself; for text columns, CHECK (JSON_VALID(raw)) works from 8.0.16.

Does JSON_VALID accept JSON5 or trailing commas?

MySQL's JSON_VALID and SQL Server's ISJSON do not. SQLite's json_valid accepts JSON5 only when you pass flags (json_valid(x, 6)). Oracle's default lax IS JSON accepts unquoted keys and single quotes; add STRICT to reject them.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.