Hi @Naomi Nosonovsky ,
Assuming that you have SQL Server 2016 or later.
SQL
DECLARE @json NVARCHAR(MAX) =
N'[
{
"id": 1,
"image": "trails/1.jpg",
"name": "Countryside Ramble",
"route": [
{
"stage": 1,
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
},
{
"stage": 2,
"description": "Curabitur interdum molestie tempus."
}
]
},
{
"id": 2,
"image": "trails/2.jpg",
"name": "Woodland Walk",
"route": [
{
"stage": 1,
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
}
]
}
]';
SELECT JSON_VALUE(parent.value, '$.id') as id
, JSON_VALUE(parent.value, '$.image') as [image]
, JSON_VALUE(parent.value, '$.name') as [name]
, JSON_VALUE(child.value, '$.stage') as stage
, JSON_VALUE(child.value, '$.description') as [description]
FROM OPENJSON(@json) AS parent
CROSS APPLY OPENJSON(parent.value, '$.route') AS child;