I pulled JSON data from a third-party API and I am trying to automate its entry into an SQL database. The format of the JSON is as follows :
{ "fields": {
"Example.FirstName": "Bob",
"Example.LastName": "Test",
"Example.Salary": "$50000"
},
"UserId": "1001231234"
}
I can retrieve the UserId, but anything within fields I am not sure how to access. I figured it would just be fields.Example.FirstName but I keep getting null. This is what I have done
Declare @JSON varchar(max)
SELECT @JSON=BulkColumn
FROM OPENROWSET (BULK 'C:\Python38\Data.JSON', SINGLE_CLOB) as import
SELECT * FROM OPENJSON (@JSON)
WITH
(
[fields.Example.FirstName] varchar(50),
[UserId] varchar(50)
)
If anyone can explain the syntax of how to access the data in fields, it would be much appreciated. I am using Microsoft SQL Server if that helps.