import json to mssql code example
Example 1: 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 2: sql server import json
DECLARE @JSON VARCHAR(MAX)
SELECT @JSON = BulkColumn
FROM OPENROWSET
(BULK 'C:\file-location\my-data.json', SINGLE_CLOB)
AS j
Example 3: sql server import json
{
"ok": true,
"data": {
"assets": {
"parcels": [{
"id": "51,100",
"x": 51,
"y": 100,
"auction_price": 4444,
"district_id": "77909d00",
"owner": "Dr Cornwallis",
"data": { "version": 0 }
},
],
total: 2500
},
},
}