SQL Server 2016 JSON Support FOR Data Warehousing Sifiso W. Ndlovu @mafiswana
Agenda Part I: Convert JSON Data to Relational Part II: Convert Relational Data to JSON
Agenda JSON Editor https://jsonformatter.curiousconcept.com/
PART I: Convert JSON Data to Relational
What Is JSON JSON (JavaScript Object Notation) is a lightweight, readable format for structuring data It is based on a subset of JavaScript language It is used primarily to transmit data between a server and web application, as an alternative to XML It is easy for humans to read and write. It is easy for machines to parse and generate
What Is JSON Sample JSON document
Convert JSON Data to Relational Requirement for Data Warehouse, T-SQL, Report development JSON by itself doesn’t not make sense to business or reporting tools
Convert JSON Data to Relational Available functions ISJSON OPENJSON JSON_VALUE
Convert JSON Data to Relational ISJSON
Convert JSON Data to Relational ISJSON Validates JSON content Returns 1 for a valid JSON dataset and 0 for invalids Demo
Convert JSON Data to Relational OPENJSON Works similar to OPENXML Takes in an object and convert its data into rows and columns Demo
Convert JSON Data to Relational JSON_VALUE Extracts a scalar value from a JSON string Demo
PART II: Convert Relational Data to JSON
Convert Relational Data to JSON Unsupported Data Types Spatial Geometry, Geography, CLR (Common Language Runtime) Supported Data Types SQL Server Data Type JSON Data Type char, nchar, varchar, nvarchar, date, datetime, datetime2, time, datetimeoffset, uniqueidentifier, money string int, bigint, float, decimal, numeric number Bit Boolean varbinary, binary, image, timestamp, rowversion BASE64-encoded string
Convert Relational Data to JSON FOR JSON Clause AUTO Mode PATH Mode Options FOR JSON Clause ROOT INCLUDE_NULL_VALUES WITHOUT_ARRAY_WRAPPER
Convert Relational Data to JSON FOR JSON Clause AUTO Mode simplest way to convert relational data into a JSON the structure of the JSON output is determined by a combination of the order of columns in your SELECT statement as well as the tables that are referenced by the SELECT statement Demo
Convert Relational Data to JSON FOR JSON Clause PATH Mode Without a dot syntax With a dot syntax
Convert Relational Data to JSON FOR JSON Clause PATH Mode Without a dot syntax When you are using it without a dot syntax, it works similar to the AUTO mode in that it will generate a JSON output based on the ordering of columns in your SELECT statement Demo
Convert Relational Data to JSON FOR JSON Clause PATH Mode With a dot syntax Used to organise the JSON output into child arrays Demo
Convert Relational Data to JSON Options FOR JSON Clause ROOT Used assign a label to the top-level array Demo
Convert Relational Data to JSON Options FOR JSON Clause INCLUDE_NULL_VALUES Default behaviour when using FOR JSON clause is that NULL values will not be included in your JSON output This can be overridden by specifying the INCLUDE_NULL_VALUES option Demo
Convert Relational Data to JSON Options FOR JSON Clause WITHOUT_ARRAY_WRAPPER Default every FOR JSON clause returns JSON data wrapped around square brackets To override this, use WITHOUT_ARRAY_WRAPPER option Demo
References www.SQLShack.com
Thank you to our sponsors
Questions