Download presentation
Presentation is loading. Please wait.
Published byLesley Watkins Modified over 5 years ago
1
Integrating REST API and SQL Server JSON Functions
Sam Nasr, MCSA, MVP NIS Technologies July 28, 2018
2
About Me Software Developer since 1995
Sam Nasr Software Developer since 1995 Sr. Software Engineer (NIS Technologies) Certifications: MCSA, MCAD, MCT, MCTS President - Cleveland C#/VB.Net User Group President - .Net Study Group Author for Visual Studio Magazine Microsoft Most Valuable Professional (since 2013)
3
General Info Down the hall (right side) Participation is encouraged
Please mute cell phones
4
Cleveland C#/VB.Net User Group
Meets every month Free of charge , open to the public All topics related to .Net Meeting info:
6
JSON JSON (JavaScript Object Notation)
Name/Value pair syntax for storing/exchanging data JSON data is Text written in JavaScript object notation Lightweight data-interchange format Self-describing and easy to understand Language independent Native JavaScript Objects JSON.Parse(): converts string into JSON JSON.Stringify(): converts JSON into string
7
JSON Sample Data { "firstName": "John", "lastName": "Smith",
"address": "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": " " }, "phoneNumbers": [ "type": "home", "number": " " "type": "office", "number": " " } ], "children": [], "spouse": null
8
SQL Server JSON Functions
JSON_VALUE: extract scalar value JSON_QUERY: extract object or array JSON_MODIFY: Updates property value in JSON string ISJSON: Returns 1 if valid JSON, else 0 OPENJSON: Transforms JSON into table with assumed columns FOR JSON: Formats the result set as JSON [PATH]: define output structure using column names/aliases. [AUTO] automatically create nested sub arrays FOR JSON PATH: Enables you to define the structure of output JSON using the column names/aliases. If you put dot-separated names in the column aliases, JSON properties will follow the naming convention. (Similar to FOR XML PATH where you can use slash separated paths.) FOR JSON AUTO: Automatically create nested JSON sub arrays based on the table hierarchy used in the query (similar to FOR XML AUTO)
9
SQL Server JSON Use Cases
Simplification of complex data models (denormalize) REST API for SPA Retail/E-commerce Log and telemetry data analysis Storing semi-structured IoT data Fully supported in 2016 and later
10
Demo JSON Functions
11
Visual Studio Project Setup
Used .Net Core 2.1 API template No HTTPS, No authentication SDK dependencies were resolved once built and packages downloaded App ran with default setup Install-Package Microsoft.EntityFrameworkCore.SqlServer Install-Package Microsoft.EntityFrameworkCore.Tools Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design
12
Demo Web API
13
Gotchas Using .Net Core 2.0 caused alot of problems because of every package install defaulted to 2.1. Reference issues shown until first build Ensure App template runs with default setup JSON_MODIFY does NOT update record in DB, only the JSON returned.
14
Recap
15
Contact Info @SamNasr Thank you for attending!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.