Presentation is loading. Please wait.

Presentation is loading. Please wait.

Meet JSON In SQL Server 2016 Russ Loski Preparations:

Similar presentations


Presentation on theme: "Meet JSON In SQL Server 2016 Russ Loski Preparations:"— Presentation transcript:

1 Meet JSON In SQL Server 2016 Russ Loski Preparations:
Have Visual Studio open with a console project created with JSON file. Clear the existing file. Open the JSON sample and have the SQL files displaying. Russ Loski

2 Gold Sponsor Silver Sponsor Bronze Sponsor Swag Sponsor
SQL Saturday Host 2 | Blog Sponsor San Antonio SQL User Group Personal Sponsor Thomas LeBlanc aka The Smiling DBA Naomi Williams aka Naomi The SQL DBA The user groups meets every 3rd Wednesday from New Horizons Training Center on 2727 NW Loop 410 #103, San Antonio, TX 78230 More info?

3 Russ Loski SQL Server ETL developer from the Dallas Fort Worth area
Member of the North Texas SQL Server Users Group Curious about structured data Regular speaker at SQL Saturdays Grand dad for active 5 year old @sqlmovers

4 Structured Or Not Structured
Structure from none to RDMS

5 Structured Or Not Structured
<?xml version="1.0"?> <catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date> </publish_date> <description>An in-depth look at creating applications with XML.</description> </book> <book id="bk102"> <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date> </publish_date> <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description> </book>

6 Structured Or Not Structured
policyID,statecode,county,eq_site_limit,hu_site_limit,fl_site_limit,fr_site_limit,tiv_2011,tiv_2012,eq_site_deductible,hu_site_deductible,fl_site_deductible,fr_site_deductible,point_latitude,point_longitude,line,construction,point_granularity 119736,FL,CLAY COUNTY,498960,498960,498960,498960,498960, ,0,9979.2,0,0, , ,Residential,Masonry,1 448094,FL,CLAY COUNTY, , , , , , ,0,0,0,0, , ,Residential,Masonry,3 206893,FL,CLAY COUNTY, , , , , , ,0,0,0,0, , ,Residential,Wood,1 333743,FL,CLAY COUNTY,0, ,0,0, , ,0,0,0,0, , ,Residential,Wood,3 172534,FL,CLAY COUNTY,0, ,0, , , ,0,0,0,0, , ,Residential,Wood,1

7 Structured Or Not Structured
ISA*00*          *00*          *12*ABCCOM         *01*       *101127*1719*U*00400* *0*P*> GS*PO* * * *1719*1421*X*004010VICS ST*834*0179 BGN*00*1* *110650****4 REF*38*SAMPLE_POLICY_NUMBER DTP*303*D8* N1*P5*COMPAN_NAME*FI* INS*Y*18*030*20*A REF*0F*SUBSCRIBER_NUMBER NM1*IL*1*JOHN DOE*R***34*1* PER*IP**HP* N3*123 SAMPLE RD N4*CITY*ST* DMG*D8*  *F HD*030 DTP*348*D8* REF*1L*INDIV_POLICY_NO SE*16*0179 GE*1*1421 IEA*1*

8 Structured Or Not Structured
Structure from none to RDMS

9 Structured Or Not Structured
Images Printed Books Book on line Web Page Web Page w/ Tables Comma Delimited Structure from none to RDMS SQL Server provides means for working with XML. It even will let you work with comma delimited files. What SQL Server 2016 is the ability to work with JSON. Also, SQL Server 2016 can parse comma delimited variables strings and column strings, but that is for another day. JSON XML { "name"="Russ", "location"="Tyler" } OLTP DB with RDMS Pure Relational model

10 Microsoft Connect What is JSON?

11 Agenda What is JSON and why is it important Reading JSON in SQL Server
Writing JSON in SQL Server

12 What is JSON JavaScript Object Notation
Lightweight data format akin to XML Self-describing Converts directly to JavaScript objects Easy to work with in JavaScript than other formats Provide definition What is JSON?

13 Simple JSON {"employees":[     {"firstName":"John", "lastName":"Doe"},     {"firstName":"Anna", "lastName":"Smith"},     {"firstName":"Peter", "lastName":"Jones"} ]} This examples comes from What is JSON?

14 JSON Examples – Data Types
Numbers: 1, 2, 3.4 – No quotes Strings: "test" , "1", "true" – Double quotes Boolean: true, false – No quotes Array: [ , ] – Square brackets surrounding comma delimited list Object: {"name1":"value1", "name2":"value2"} Null: null – This indicates empty item. What is JSON?

15 JSON Examples - Arrays [ 1 , 2, 3, 4, 5]
[ "Russ" , "Gail" , "Don" , "Julie"] [ {"phoneType" : "cell" , "number" : " " } , {"phoneType" : "home", "number" : " " } ] [ 1, "Russ", { "address1" : "444 Main", "city" : "Tyler" } ] You can have arrays of any type. And the array does need to have items of the same type. What is JSON?

16 Why JSON? Agile. No structure up front Light. Not the tag structure
My focus in this slide is not to argue for or against JSON. It is simply to repeat some of the arguments for JSON.

17 Reading JSON in SQL Server 2016
Reading JSON into row set Extracting single value from JSON Identifying JSON Reading JSON

18 JSON Data Type? No JSON data type
Use string (varchar, nvarchar up to max) Richer than XML support in early 2000s Reading JSON

19 Reading JSON into Row Set
OPENJSON ( NVARCHAR Column/Variable/Constant , JSON Path Expression ) Reading JSON

20 OpenJSON Examples SELECT * FROM OPENJSON (@var, N'$')
SELECT * FROM tbl OUTER APPLY OPENJSON(tbl.Col, N'$.property') v SELECT * FROM tbl OUTER APPLY OPENJSON(tbl.Col, N'$.property) WITH ( Prop1 VARCHAR(20) , Prop2 INT N'$.OtherProperty' , Prop3 date N'strict $.Prop3' ) as v Reading JSON

21 Reading value from JSON
JSON_Value ( NVARCHAR Column/Variable/Constant , JSON Path Expression ) Reading JSON

22 Reading JSON document from JSON
JSON_Query ( NVARCHAR Column/Variable/Constant , JSON Path Expression ) Reading JSON

23 JSON_Value/JSON_Query Examples
SELECT JSON_Value N'$.property') SELECT JSON_Value( tbl.Col, N'$.property') FROM tbl SELECT JSON_Query N'$.property') SELECT JSON_Query( tbl.Col, N'$.property') Reading JSON

24 Demo Reading JSON Reading JSON

25 Writing JSON FOR JSON AUTO/PATH Options: Writing JSON
INCLUDE_NULL_VALUES WITHOUT_ARRAY_WRAPPER ROOT('root') Writing JSON

26 Demo FOR JSON Writing JSON
The query that I use displays sales orders from the Adventureworks database. I deliberately sort the output in order to demonstrate that order matters for FOR JSON AUTO I think that I will have the entire query formatted almost the way that I want. Change the table name aliases using the design tool. The order of the tables in the join matters for how the JSON is formatted. Writing JSON

27 Use Cases for JSON One-off queries Analysis of JSON data
ETL. Loading JSON data into structured database Closing?

28 References https://msdn.microsoft.com/en-US/library/dn921897.aspx
the-good-the-bad-and-the-ugly/


Download ppt "Meet JSON In SQL Server 2016 Russ Loski Preparations:"

Similar presentations


Ads by Google