I want to import a big JSON file with this structure:
{
"series_id":"NG.RL2R04SOK_1.A",
"name":"Oklahoma Natural Gas Plant Liquids, Reserves Revision Decreases, Annual",
"units":"Million Barrels",
"f":"A",
"unitsshort":"MMbbl",
"description":"Oklahoma Natural Gas Plant Liquids, Reserves Revision Decreases",
"copyright":"None","source":"EIA, U.S. Energy Information Administration",
"iso3166":"USA-OK",
"start":"1979",
"end":"2008",
"last_updated":"13-AUG-13 11.49.51 AM",
"data":[
["2008","136"],
["2007","73"],
...
["1980","69"],
["1979","54"]
]
}
into a SQL Server database.
Usually I use VB.net to import CSV/TXT/Excel into this database, but I have no knowledge of JSON.
Is there a simple way to do that ?
Thanks a lot
In SQL Server 2016 you can open (and import) json files directly using TSQL:
SELECT import.*
FROM OPENROWSET (BULK 'f:\import.json', SINGLE_CLOB) as j
CROSS APPLY OPENJSON(BulkColumn)
WITH(
[series_id] nvarchar(100),
[name] nvarchar(100),
[units] nvarchar(100),
[f] nvarchar(100),
[unitsshort] nvarchar(100),
[description] nvarchar(100),
[copyright] nvarchar(100),
[iso3166] nvarchar(100),
[start] int,
[end] int,
[last_updated] nvarchar(100),
[data] nvarchar(100)
) AS import
This query returns a table containing data read from json file and organized with the columns specified in the WITH
clause.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.