ISJSON (Transact-SQL)
Applies to: SQL Server 2016 (13.x)
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Tests whether a string contains valid JSON.
Transact-SQL Syntax Conventions
Syntax
ISJSON ( expression )
Arguments
expression
The string to test.
Return Value
Returns 1 if the string contains valid JSON; otherwise, returns 0. Returns null if expression is null.
Does not return errors.
Remarks
ISJSON does not check the uniqueness of keys at the same level.
Examples
Example 1
The following example runs a statement block conditionally if the parameter value @param
contains valid JSON.
DECLARE @param <data type>
SET @param = <value>
IF (ISJSON(@param) > 0)
BEGIN
-- Do something with the valid JSON value of @param.
END
Example 2
The following example returns rows in which the column json_col
contains valid JSON.
SELECT id, json_col
FROM tab1
WHERE ISJSON(json_col) > 0