SQL Server OPENJSON read nested json

前端 未结 3 1815
生来不讨喜
生来不讨喜 2020-12-02 08:21

I have some json that I would like to parse in SQL Server 2016. There is a hierarchy structure of Projects->Structures->Properties. I would like to write a query that pars

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 09:10

    If you reference JSON object or array you need to specify AS JSON clause:

    select IdProject, Name, structures
    from   openjson (@json)
    with
    (
        IdProject uniqueidentifier,
        Name nvarchar(100),
        structures nvarchar(max) AS JSON
    ) as Projects
    

    See FAQ: https://msdn.microsoft.com/en-us/library/mt631706.aspx#Anchor_6

    If you want to apply OPENJSON on the returned structures array, you can use something like following code:

    select IdProject, Name, structures
    from   openjson (@json)
    with
    (
        IdProject uniqueidentifier,
        Name nvarchar(100),
        structures nvarchar(max) AS JSON
    ) as Projects 
         CROSS APPLY OPENJSON (structures) WITH (......)
    

提交回复
热议问题