Skip to content

Instantly share code, notes, and snippets.

@christianarg
Last active April 2, 2021 10:24
Show Gist options
  • Save christianarg/0a7afd4382c7637f10d1497472724d97 to your computer and use it in GitHub Desktop.
Save christianarg/0a7afd4382c7637f10d1497472724d97 to your computer and use it in GitHub Desktop.
/*
source: https://www.sqlshack.com/import-json-data-into-sql-server/
sample json
[
{
"id": "1",
"name": "paco"
},
{
"id": "2",
"name": "jose"
},
{
"id": "3",
"name": "manolo"
}
]
*/
DECLARE @JSON NVARCHAR(max)
SELECT @JSON=BulkColumn
FROM OPENROWSET (BULK 'D:\CODE\jsonlist.json', SINGLE_CLOB) import
SELECT * INTO JSONTable
FROM OPENJSON (@JSON)
WITH
(
id NVARCHAR(5),
name NVARCHAR(50)
)
SELECT * FROM JSONTable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment