I am currently able to parse most of a JSON file using SQL Server's OPENJSON WITH (... syntax. However, this particular file contains nested arrays which I do not know how to handle.
Many of the examples I read reference JSON as a variable. In this case I am calling a file:
select DEV_JSON.*
from OPENROWSET
(BULK 'C:\Users\Myuser\Documents\JSON_extract.json', SINGLE_CLOB) as my_datafile
CROSS APPLY OPENJSON(BulkColumn)
WITH
(DOC_ID varchar(100) '$.doc._id',
DOC_REV varchar(45) '$.doc._rev',
DELY_APPL_NAME varchar(20) '$.doc.delivery.application',
DELY_SENT_BY varchar(25) '$.doc.delivery.sender.id',
DELY_SENT_TYPO varchar(20) '$.doc.delivery.sender.type',
.....
....
...
..) as DEV_JSON
One of the attributes contains a nested array. Below I have copied the 1st 5 attributes of my JSON, as well as the nested "recipients" array.
How do I structure my SQL to parse this section?
"doc": {
"_id": "[email protected]",
"_rev": "3-e119db13dae8d50ae0c4579ba9c87fc9",
"delivery": {
"application": "App_XYZ",
"sender": {
"id": "[email protected]",
"type": "user"
},
"recipients": [{
"type": "email",
"recipient": "\"Artzer, Daniel J\" <[email protected]>",
"sentTS": "2017-10-18T13:04:00.133Z"
},
{
"type": "email",
"recipient": "\"Higgins, Laura L\" <[email protected]>",
"sentTS": "2017-10-18T13:04:00.133Z"
},
{
"type": "email",
"recipient": "\"Friedman, Brian\" <[email protected]>",
"sentTS": "2017-10-18T13:04:00.133Z"
},
{
"type": "email",
"recipient": "\"Garcia, Charlie M\" <[email protected]>",
"sentTS": "2017-10-18T13:04:00.133Z"
}
]
},