I have the following JSON
DECLARE @json NVARCHAR(max) = '
{
"source": "one",
"dataSetId":"a3d5-14fda14",
"data": [
{
"FieldId": 10
}
]
}
'
and need to parse the values to the table.
I have tried:
-- meta
SELECT *
FROM OPENJSON(@json)
WITH ( source NVARCHAR(20)
,dataSetId NVARCHAR(50)
,FieldId INT '$.data.FieldId'
)
-- array
SELECT *
FROM OPENJSON(@json, '$.data')
WITH ( source NVARCHAR(20)
,dataSetId NVARCHAR(50)
,FieldId int '$.FieldId'
)
It works to get source and dataSetId columns or to get FieldId column, but I am still unable to merge both solution, to parse both non-array and array data.
The SELECT should return all the data in one query.