Here's a snippet of the json data:
{
"columns": [
"State",
"Honey producing colonies",
"Yield per colony",
"Production",
"Stocks December 15",
"Average price per pound",
"Value of production",
"Year"
],
"rows": [
[
"AL",
"41",
"20",
"820",
"33",
"0.54",
"443",
"1989"
],
[
"AZ",
"78",
"45",
"3510",
"1158",
"0.55",
"1931",
"1989"
]
]
}
And I've created a table here:
CREATE TABLE HoneyTbl (
"State" VARCHAR(MAX),
"Honey producing colonies" VARCHAR(MAX),
"Yield per colony" VARCHAR(MAX),
"Production" VARCHAR(MAX),
"Stocks December 15" VARCHAR(MAX),
"Average price per pound" VARCHAR(MAX),
"Value of production" VARCHAR(MAX),
"Year" VARCHAR(MAX),
)
And now I'm trying to extract the json data of rows here:
Declare @Json varchar(max)
SELECT @Json = BulkColumn
FROM OPENROWSET (BULK 'C:\Temp\honey.json', SINGLE_CLOB) as j
SELECT * FROM OPENJSON (@Json, '$.rows')
But I'm stuck as it's outputting as an array like this:
+---+------------------------------------------------------------------+
|key| value |
+---+------------------------------------------------------------------+
| 0 | [ "AL", "41", "20", "820", "33", "0.54", "443", "1989" ] |
+---+------------------------------------------------------------------+
How can I select individual values from that array and insert them into my table? I need each one to be under a different column. (Need row values to line up with columns)