Building tabular results from JSON data in SQL Server
A common requirement in reporting is to flatten the JSON data so that it can be easily used in reporting or by analytics tools such as Power BI. While some of these tools can interrogate and explore JSON documents, they tend to work better with tabular formatted data. One common use case we have seen is creating views using some of the techniques we are about to demonstrate to have tabular versions of JSON data ready for reporting and analytics tools to use. Our final example will create such a view for you to have as a reference.
When creating these views, our primary function of choice is OPENJSON
. By using this, combined with the CROSS APPLY
operator, we can return rows of data from JSON documents joined with relational data for ease of use.
In our example, we are going to create a set of queries and bring them together into a single view that will contain the customer information from the table combined with some order...