You can use the ISJSON function in T-SQL to check if a string is a valid JSON string. The ISJSON function returns 1 if the input string is a valid JSON string and 0 if it is not. Here is an example of how you can use the ISJSON function:
DECLARE @Json NVARCHAR(MAX) = ‘{
“id”: “2”,
“body”: “Media Msg”
}’
IF ISJSON(@Json) = 1
BEGIN
PRINT ‘Valid JSON’
END
ELSE
BEGIN
PRINT ‘Invalid JSON’
END
In this example, the ISJSON function is used to check if the string stored in the @Json variable is a valid JSON string. If the string is valid, the PRINT statement outputs “Valid JSON”. If the string is not valid, the PRINT statement outputs “Invalid JSON”.