
ProductID2 INT '$.OrderDetail.ProductID', UnitPrice1 INT '$.OrderDetail.UnitPrice', ProductID1 INT '$.OrderDetail.ProductID', You can also specify the child elements with full path by using the dollar sign “$” inside the WITH() clause (instead at column level above), like below: OrderIDĜustomerID ProductID1 UnitPrice1 ProductID2 UnitPrice2 In this case what you have to do is, use the array positions with square brackets (“”) in your query and call out separate columns for each child element, like below: Because, here you are having array of child elements with OrderDetail node (notice the square-bracket after “OrderDetail”: node), thus the Query is not able to find the key on the path.

Instead you get ProductID & UnitPrice column values as NULL.

You might be expecting 2 rows with same OrderID & CustomerID, with different ProductID & UnitPrice, right? Using OPENJSON() function:īut, if you have more than one nested elements the same query will give just 1 row with NULL values under the child columns, like this. Here, we have just one nested element, and the OPENJSON() function will get you the child elements values: We will see usage of both the functions in our example below: – JSON_Value() Scalar function: returns a value from JSON on the specified path.

– OPENJSON() Table valued function: parses JSON text and returns rowset view of JSON. Native JSON support in SQL Server 2016 provides you few functions to read and parse your JSON string into relational format and these are: Today in this post I’ll talk about how to read/parse JSON string with nested array of elements, just like XML. In my I discussed about how to Import or Read a JSON string and convert it in relational/tabular format in row/column from.
