Sql-server – Can SQL Server 2016 validate JSON on insert

jsonsql serversql-server-2016

Currently SQL Server 2016 CTP 3 and later releases support NVARCHAR(max) fields with JSON content. However since the type NVARCHAR(max) is totally free-form, there is no constraint on these fields.

Can I declare a constraint that prevents insertion of a non-null value that is not valid JSON?

Best Answer

Add this constraint:

ALTER TABLE [dbo].[Resource] 
 ADD CONSTRAINT [RESOURCE_ExtJSON_VALID] 
   CHECK ( ISJSON( ExtJSON )> 0 )