ISJSON (Transact-SQL)ISJSON (Transact-SQL)

適用範圍:Applies to: 是SQL Server 2016 (13.x)SQL Server 2016 (13.x)yesSQL Server 2016 (13.x)SQL Server 2016 (13.x) 及更新版本 是Azure SQL DatabaseAzure SQL DatabaseYesAzure SQL DatabaseAzure SQL Database 是Azure SQL 受控執行個體Azure SQL Managed InstanceYesAzure SQL 受控執行個體Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics適用範圍:Applies to: 是SQL Server 2016 (13.x)SQL Server 2016 (13.x)yesSQL Server 2016 (13.x)SQL Server 2016 (13.x) and later 是Azure SQL DatabaseAzure SQL DatabaseYesAzure SQL DatabaseAzure SQL Database 是Azure SQL 受控執行個體Azure SQL Managed InstanceYesAzure SQL 受控執行個體Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics

測試字串是否包含有效的 JSON。Tests whether a string contains valid JSON.

主題連結圖示 Transact-SQL 語法慣例Topic link icon Transact-SQL Syntax Conventions

語法Syntax

ISJSON ( expression )  

引數Arguments

expressionexpression
要測試的字串。The string to test.

傳回值Return Value

若字串包含有效的 JSON,則傳回 1;否則傳回 0。Returns 1 if the string contains valid JSON; otherwise, returns 0. expression 為 null,則傳回 null。Returns null if expression is null.

不會傳回錯誤。Does not return errors.

備註Remarks

ISJSON 不會檢查相同層級中索引鍵的唯一性。ISJSON does not check the uniqueness of keys at the same level.

範例Examples

範例 1Example 1

下列範例會在參數值 @param 包含有效的 JSON 時條件式的執行陳述式區塊。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

範例 2Example 2

下列範例會傳回資料行 json_col 中包含有效 JSON 的資料列。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 

另請參閱See Also

JSON 資料 (SQL Server)JSON Data (SQL Server)