Originally published at SQL & Cloud Lab .
This post was drafted with AI assistance.
Modern applications send and receive JSON everywhere, and SQL Server has built-in functions to read, write and query it, available since SQL Server 2016 and in Azure SQL. Used well, they let you store flexible data and exchange it with APIs without extra code. Used badly, they create slow, hard-to-query tables. Here is the practical toolkit.
Storing JSON
Traditionally JSON is stored in an NVARCHAR column, with a check constraint to keep it valid:
CREATE TABLE dbo . EmployeeSettings ( EmployeeId INT PRIMARY KEY , Settings NVARCHAR ( MAX ) NOT NULL CONSTRAINT CK_EmployeeSettings_IsJson CHECK ( ISJSON ( Settings ) = 1 ) );
INSERT INTO dbo .…