ISJSON function validates whether the string parameter supplied to it is a valid JSON or not. If supplied string is a valid JSON then it will return value as 1, otherwise it returns the value 0. In case input is a NULL then it returns output as NULL.
Syntax:
ISJSON( String_Expression )
WHERE String_Expression can be a table column or a string (i.e. Varchar/NVarchar) variable or a string constant. And this string expression is evaluated to check whether it is a valid JSON.
[ALSO READ]:
- Native JSON Support in Sql Server 2016
- FOR JSON Clause in Sql Server 2016
- OPENJSON Function in Sql Server 2016
- JSON_VALUE Function in Sql Server 2016
- JSON_QUERY Function in Sql Server 2016
- lax and strict JSON Path modes in Sql Server 2016
- Indexing Strategy for JSON Value in Sql Server 2016
Let us understand this function with extensive list of examples:
Example 1: Input is a valid JSON, in this case the ISJSON function will return value as 1
DECLARE @JSONText NVarchar(Max) = '[{"Id":1,"Name":"Basavaraj"}, {"Id":2,"Name":"Kalpana"}]' IF ISJSON ( @JSONText ) = 1 PRINT 'Valid JSON'
Example 2: Input is an InValid JSON, in this case the ISJSON function will return value as 0
DECLARE @JSONText NVarchar(Max) = 'Basavaraj' IF ISJSON ( @JSONText ) = 0 PRINT 'InValid JSON'
Example 3: Input is a NULL value, in this case the ISJSON function will return value as 0
SELECT ISJSON ( NULL ) 'ISJSON RESULT'
- Native JSON Support in Sql Server 2016
- DROP IF EXISTS Statement in Sql Server 2016
- Compare Execution Plans in Sql Server 2016
- Live Query Statistics in Sql Server 2016
- DATEDIFF_BIG Function in Sql Server 2016
- Difference between DATEDIFF and DATEDIFF_BIG functions in Sql Server
- SESSION_CONTEXT in Sql Server 2016