Formatting results as JSON in SQL Server
To demonstrate how we want JSON and its usage within SQL, we will be creating a table and inserting JSON into it for use throughout the rest of this chapter. In this section, we will build a query that will generate JSON that can be stored and a couple of tables for illustration and demonstration purposes for extracting JSON data. We will be using FOR JSON
and its related options to generate JSON data to be stored in our table.
Throughout the rest of this chapter, we will be working with data from the WideWorldImporters
database. If you want to follow along step by step, now is the time to open SQL Server Management Studio or Azure Data Studio, depending on the platform you have decided to use. We recommend that you use Azure Data Studio as it works best with JSON data results. If you only have SQL Server Management Studio available, the results will still be available to you but will be formatted in an XML format as opposed to a JSON format...