Read JSON file
Reads a JSON file from a SharePoint document library without downloading it to disk (streaming approach).
Standard SQL query example
This is the base query accepted by the connector. To execute it in SQL Server, you have to pass it to the Data Gateway via a Linked Server. See how to accomplish this using the examples below.
SELECT * from get_json_file
WITH(
DriveId='b!0zqXLXXJh0uUMzl-JXAd9Ztngc-5utVDqRyD2lKpD2535-11HLQTR5z4hOzmA7Q0'
, FileId='root:/MyFolder/dump.json:'
--, FileId='01R65QTTRARZ42C4BN6FF2WOH3AONX4GUW' -- by ID (preferred)
, Filter='$.store.books[*]' --or just blank (see help file for more filter examples)
--to read compressed file use below way
--, FileId='root:/MyFolder/dump.json.gz:'
--, FileCompressionType='GZip' --None, GZip, Zip
)
Using OPENQUERY in SQL Server
SELECT * FROM OPENQUERY([LS_TO_SHAREPOINT_ONLINE_IN_GATEWAY], 'SELECT * from get_json_file
WITH(
DriveId=''b!0zqXLXXJh0uUMzl-JXAd9Ztngc-5utVDqRyD2lKpD2535-11HLQTR5z4hOzmA7Q0''
, FileId=''root:/MyFolder/dump.json:''
--, FileId=''01R65QTTRARZ42C4BN6FF2WOH3AONX4GUW'' -- by ID (preferred)
, Filter=''$.store.books[*]'' --or just blank (see help file for more filter examples)
--to read compressed file use below way
--, FileId=''root:/MyFolder/dump.json.gz:''
--, FileCompressionType=''GZip'' --None, GZip, Zip
)')
Using EXEC in SQL Server (handling larger SQL text)
The major drawback of OPENQUERY is its inability to incorporate variables within SQL statements.
This often leads to the use of cumbersome dynamic SQL (with numerous ticks and escape characters).
Fortunately, starting with SQL 2005 and onwards, you can utilize the EXEC (your_sql) AT [LS_TO_SHAREPOINT_ONLINE_IN_GATEWAY] syntax.
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * from get_json_file
WITH(
DriveId=''b!0zqXLXXJh0uUMzl-JXAd9Ztngc-5utVDqRyD2lKpD2535-11HLQTR5z4hOzmA7Q0''
, FileId=''root:/MyFolder/dump.json:''
--, FileId=''01R65QTTRARZ42C4BN6FF2WOH3AONX4GUW'' -- by ID (preferred)
, Filter=''$.store.books[*]'' --or just blank (see help file for more filter examples)
--to read compressed file use below way
--, FileId=''root:/MyFolder/dump.json.gz:''
--, FileCompressionType=''GZip'' --None, GZip, Zip
)'
EXEC (@MyQuery) AT [LS_TO_SHAREPOINT_ONLINE_IN_GATEWAY]