Hi @Pulipati Vedanth ,
Thanks for using Microsoft Q&A !!
If you do not have any specific needs to create a FMT file then you can use OPENROWSET
with SINGLE_CLOB
to import JSON data from a Blob Storage using a query like below -
SELECT id,[name],author FROM OPENROWSET(
BULK 'input/books.json',
DATA_SOURCE = 'storageadftutorial',
SINGLE_CLOB
) AS DataFile
CROSS APPLY OPENJSON(BulkColumn)
WITH (id NCHAR(1000),
[name] NCHAR(500),
author NCHAR(500)) as book
Please note here that the data from JSON file is returned as BulkColumn
which you can join with OPENJSON
which returns each JSON array object as a single row, which you can insert into the required table.
books.json sample content
[
{
"id" : "978-0641723445",
"cat" : ["book","hardcover"],
"name" : "The Lightning Thief",
"author" : "Rick Riordan",
"series_t" : "Percy Jackson and the Olympians",
"sequence_i" : 1,
"genre_s" : "fantasy",
"inStock" : true,
"price" : 12.50,
"pages_i" : 384
}
,
{
"id" : "978-1423103349",
"cat" : ["book","paperback"],
"name" : "The Sea of Monsters",
"author" : "Rick Riordan",
"series_t" : "Percy Jackson and the Olympians",
"sequence_i" : 2,
"genre_s" : "fantasy",
"inStock" : true,
"price" : 6.49,
"pages_i" : 304
}
]
SQL Table:
Create table books( Id NCHAR(1000), [Name] NCHAR(500), Author NCHAR(500) )
Use below to insert into books table
INSERT INTO books with (TABLOCK) (id,[name],author)
SELECT id,[name],author FROM OPENROWSET(
BULK 'input/books.json',
DATA_SOURCE = 'storageadftutorial',
SINGLE_CLOB
) AS DataFile
CROSS APPLY OPENJSON(BulkColumn)
WITH (id NCHAR(1000),
[name] NCHAR(500),
author NCHAR(500)) as book
Please refer to Import JSON documents into SQL Server for details.
Hope this helps.
Thanks
Saurabh
----------
Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.