Issue : How to Load Multiple Json Files to SQL Server Table with File Name In SSIS - SSIS Tutorial 2021
In this video you are going to learn how to load Multiple JSON file to SQL Server Table With File Name in SSIS.I have generated Couple of JSON Files online so we can use for our demo.
Below is JSON File Snapshot how its looks like.
Step 1:
Open SQL Server Management Studio (SSMS) and use the script I have provided below, First of all we have to declare the variable which is "Declare @JSON varchar (max), which I have Highlighted in this picture.
Declare @JSON varchar(max)
SELECT @JSON=BulkColumn
FROM OPENROWSET (BULK 'c:\MyJsonFile.json', SINGLE_CLOB) import
insert into dbo.SSISJson
SELECT * FROM OPENJSON @JSON)
WITH
(
[ID] INT,
[first_name] varchar(100),
[last_name] varchar(100),
[email] varchar(100),
[gender] varchar(20),
[ip_address] varchar(10)
)
By using OPENROWSET function we have imported the JSON Files in @JSON variable.
OPENJSON is table value function that can convert JSON data into columns and rows. As you can see below I have use OPENJSON and provided our variable @JSON as input so we can get data in tabular format.
Step 1 :
Create Table By Using Below Command:
create table dbo.SSISJson(
[id] int,
[first_name] varchar(100),
last_name] varchar(100)
[email] varchar(100),
[gender] nvarchar(20)
[ip_address] varchar(10),
filename varchar (1000))
Next : insert data by using below command:
insert into dbo.SSISJson and Execute
In Foreach Loop Container we have to select the type & Path of our JSON Files
Step 1:
Next Click on Expressions Click on the Property & select SQL Statement source then Click on Expression & Copy Paste The Below Given Command in Expression and add the file Path Which is created earlier.
Declare @JSON varchar(max)
SELECT @JSON=BulkColumn
FROM OPENROWSET (BULK "++", SINGLE_CLOB) import
insert into dbo.SSISJson
SELECT * FROM '"++"' as filename FROM OPENJSON @JSON
WITH
(
[ID] INT,
[first_name] varchar(100),
[last_name] varchar(100),
[email] varchar(100),
[gender] varchar(20),
[ip_address] varchar(10)
)
Click OK and Go To The SSMS and Read The Data : Select * from dbo.SSISJson and Execute Then Truncate the Table Back To Visual Studio and Execute our Package.
Next Go Back to SSMS And Verify the File
Video Demo: How to Load Multiple Json Files to SQL Server Table with File Name In SSIS