I am trying to insert a JSON file into a table using SQL Server's "OPENJSON WITH (..." syntax). However, this file contains nested arrays, which I do not know how to handle.
Here is my JSON file:
}
"Person_ID":["7120","4816","6088"],
"Occupant_Type":["ADT","SCD","MCD"],
"Occupant_Gender":["M","F","M"],
"Occupant_Height":[180,102,127],
"Occupant_Weight":[68,20,22],
"Occupant_Age":[23,2.5,5.5],
"Occupied_Region":[],
"Occupant_Type_Region":[]
}
and here is the code I tried to use:
DECLARE @test_data varchar(max)
SELECT @test_data = BulkColumn
FROM OPENROWSET (BULK 'C:\Users\ofiri\OneDrive\Desktop\אופיר\BWR\Data for testing\chevrolet_spark json files\03.03.2020 copy14', SINGLE_CLOB) import
insert into Person1([ID])
select [ID]
from openjson(@test_data,'$."Person_ID"')
with(
[ID] VARCHAR '$."Person_ID"'
)
cross apply
openjson (@test_data,'$."Occupant_Type"')
But after I run the code, all the attributes in the table are null.
How can I insert the values into my table?