import json to sql code example

Example 1: insert json into sql

SELECT *
FROM OPENJSON(@json)
 WITH (id int 'strict $.id',
       firstName nvarchar(50) 'strict $.info.name',
       lastName nvarchar(50) '$.info.surname',
       age int,
       dateOfBirth datetime2)

Example 2: sql server import json

SELECT *
FROM OPENJSON (@JSON, '$.data.assets.parcels') 
WITH (id VARCHAR(7), 
		x INT,
		y INT,
		price INT '$.auction_price') -- new column name
)

Example 3: sql server import json

DECLARE @JSON VARCHAR(MAX)

SELECT @JSON = BulkColumn
FROM OPENROWSET 
(BULK 'C:\file-location\my-data.json', SINGLE_CLOB) 
AS j