From the course: Microsoft SQL Server 2016 Essential Training
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Converting JSON to tabular data - SQL Server Tutorial
From the course: Microsoft SQL Server 2016 Essential Training
Converting JSON to tabular data
- [Narrator] SQL Server 2016 also provides some tools for us to read in data that is formatted as JSON and convert that data to tabular data. I've staged some code for you in your Exercise Files. Take all of that and copy it into a new Query window. On the very first line I am creating a variable to hold our JSON, and then the next few lines sets the value of that variable to some JSON content. I have this content in line with the script. It could just as easily be read from a file. And then once that data is in the JSON variable, we're going to run a select statement. And in the from clause, rather than put the name of a table, we'll say FROM OPENJSON and pass it the variable that contains the JSON. Then we need to say with and we need to outline what columns we would like to return and map those columns to some of the keys in the JSON content. We will return a column called FirstName that maps to the JSON field of…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.