Is it possible to output a nested array into a table?
I intend to loop over the orders array and capture the line_item id's for the current iteration.
SQL
DECLARE @json NVARCHAR(4000) = N'
{
"orders":[
{
"id":123,
"line_items":[
{
"id":1
},
{
"id":2
}
]
}
]
};'
SELECT
[LineId]
FROM OPENJSON (@json, '$.orders.line_items') WITH (
[LineId] BIGINT '$.id'
);
Desired output
| id |
|---|
| 1 |
| 2 |
OPENJSON (@json, '$.orders[0].line_items')