ISJSON Function: It is a validation function that check string is formed JSON or not. It checks the input string is JSON or not. It returns Boolean value.
If the input string is valid JOSN format, it will return 1 otherwise it will return 0.
SYNTAX: ISJSON(input_string )
Where input_string can be type of, VARCHAR, NVARCHAR.
Example 1: ISJSON function will return value as 1 if Input is a valid JSON.
DECLARE @inputJSON_string NVarchar(Max) = '[{"ENAME": "ALOK","JOB": "ADMIN"}]'
IF ISJSON ( @inputJSON_string ) = 1
PRINT 'Valid JSON'
OUTPUT:-
Valid JSON
Example 2: ISJSON function will return value as 0 if Input is an Invalid JSON.
DECLARE @inputJSON_string NVarchar(Max) = 'alok singh'
IF ISJSON ( @inputJSON_string ) = 0
PRINT 'InValid JSON'
OUTPUT:-
InValid JSON
Remark: - Input is a null value, and then ISJSON function will return 0.
DECLARE @inputJSON_string NVarchar(Max) = ''
IF ISJSON ( @inputJSON_string ) = 1
PRINT 'Valid JSON'
IF ISJSON ( @inputJSON_string ) = 0
PRINT 'InValid JSON'
OUTPUT:-
InValid JSON


0 comments:
Post a Comment
Note: only a member of this blog may post a comment.