SlideShare a Scribd company logo
Demystifying JSON in SQL
Server
BY KRISTIN FERRIER
About Me – Kristin Ferrier
 18+ Years in IT
 Principal Consultant at Ferrier Solutions
 Full stack web developer with specialty and passion for data
 Twitter: @SQLEnergy
 Techlahoma Slack: @EnergyDev
 GitHub: @EnergyDev
What we’ll cover
 What is JSON?
 Why use JSON?
 JSON functionality in SQL Server (most of our time will be spent here)
 Built-in functions
 OPENJSON
 FORJSON
 More…
What is JSON?
JSON is data
What is JSON?
JSON is data
in the form of a JavaScript object
But with stricter rules
Like a string must be enclosed in quotation marks
Above is a practical definition. Officially JSON is “a data exchange format that was created from a subset of the literal object notation in JavaScript”
JSON Example
[
{
"QuoteID": 1,
"Franchise": "Star Wars",
"Character": "Yoda",
"QuoteText": "Do. Or do not. There is no try."
},
{
"QuoteID": 2,
"Franchise": "The Librarians",
"Character": "Cassandra",
"QuoteText": "Mathemagics. I like it.."
}
]
Why JSON?
 JSON is a very popular data format used for exchanging data in modern web and
mobile applications.
Web / Mobile App Web API
JSON
JSON
Why JSON over XML?
 With respect to XML
 JSON is more popular in modern development
 JSON is lighter
 JSON support in SQL Server is simpler
Side by Side
JSON XML
JSON Functionality in SQL Server
 Available starting with SQL Server 2016 and Azure SQL Database
 Built-in functions
 Validate JSON and Insert/Update/Delete data within JSON
 OPENJSON
 JSON => Tabular
 FORJSON
 Tabular => JSON
 More…
 Indexing, constraints, etc.
JSON Built-in Functions
 ISJSON – Validate that text is formatted as JSON
ISJSON(@json)-> bit (0, 1, or null)
 JSON_VALUE – Extract value from JSON text
JSON_VALUE(@json, '$.FranchiseID') -> NVARCHAR(4000)
 JSON_QUERY – Extract JSON fragment from JSON text
JSON_QUERY(@json, '$.Characters') -> NVARCHAR(MAX)
 JSON_MODIFY – Update, delete, or add properties in JSON text
JSON_MODIFY(@json, '$.FranchiseProducer', 'Devlin') -> NVARCHAR(MAX)
JSON Built-in Functions
DEMO TIME
OPENJSON
 Converts JSON to table data
OPENJSON
OPENJSON
DEMO TIME
FOR JSON
 Tabular data => JSON
 FOR JSON AUTO
 Defaults JSON structure
 Some customization
 Requires FROM clause
 FOR JSON PATH
 Customize overall JSON structure
 Doesn’t require FROM clause
FOR JSON
FOR JSON
DEMO TIME
Additional features
 ISJSON constraints on JSON fields
CONSTRAINT ensure_episodeJson CHECK (ISJSON(EpisodeJson) = 1)
 Indexing
ALTER TABLE dbo.Episode
ADD vDirector AS JSON_VALUE(EpisodeJSON, '$.director')
CREATE INDEX idx_episode_json_director
ON dbo.Episode(vDirector)
Q&A and Thank You
Q&A
Catch up with me later
 Twitter @SQLEnergy
 Techlahoma Slack @EnergyDev

More Related Content

Similar to Demystifying JSON in SQL Server

Native JSON Support in SQL2016
Native JSON Support in SQL2016Native JSON Support in SQL2016
Native JSON Support in SQL2016
Ivo Andreev
 
SQL to JSON
SQL to JSONSQL to JSON
SQL to JSON
kristinferrier
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
Rafael Montesinos Muñoz
 
Oracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseOracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory Database
Marco Gralike
 
Going Native: Leveraging the New JSON Native Datatype in Oracle 21c
Going Native: Leveraging the New JSON Native Datatype in Oracle 21cGoing Native: Leveraging the New JSON Native Datatype in Oracle 21c
Going Native: Leveraging the New JSON Native Datatype in Oracle 21c
Jim Czuprynski
 
UKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the DatabaseUKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the Database
Marco Gralike
 
Java-JSON-Jackson
Java-JSON-JacksonJava-JSON-Jackson
Java-JSON-Jackson
Srilatha Kante
 
Starting with JSON Path Expressions in Oracle 12.1.0.2
Starting with JSON Path Expressions in Oracle 12.1.0.2Starting with JSON Path Expressions in Oracle 12.1.0.2
Starting with JSON Path Expressions in Oracle 12.1.0.2
Marco Gralike
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesBasics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examples
Sanjeev Kumar Jaiswal
 
Store non-structured data in JSON column types and enhancements of JSON
Store non-structured data in JSON column types and enhancements of JSONStore non-structured data in JSON column types and enhancements of JSON
Store non-structured data in JSON column types and enhancements of JSON
Alireza Kamrani
 
JSON Processing and mule
JSON Processing and muleJSON Processing and mule
JSON Processing and mule
Santhosh Gowd
 
Json
JsonJson
Json
JsonJson
SQL gene in NoSQL
SQL gene in NoSQLSQL gene in NoSQL
SQL gene in NoSQL
Cihan Biyikoglu
 
java script json
java script jsonjava script json
java script json
chauhankapil
 
Json
JsonJson
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web Stack
GaryCoady
 
Json
JsonJson
Json at work overview and ecosystem-v2.0
Json at work   overview and ecosystem-v2.0Json at work   overview and ecosystem-v2.0
Json at work overview and ecosystem-v2.0
Boulder Java User's Group
 
Json
JsonJson
Json
soumya
 

Similar to Demystifying JSON in SQL Server (20)

Native JSON Support in SQL2016
Native JSON Support in SQL2016Native JSON Support in SQL2016
Native JSON Support in SQL2016
 
SQL to JSON
SQL to JSONSQL to JSON
SQL to JSON
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
 
Oracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory DatabaseOracle Database - JSON and the In-Memory Database
Oracle Database - JSON and the In-Memory Database
 
Going Native: Leveraging the New JSON Native Datatype in Oracle 21c
Going Native: Leveraging the New JSON Native Datatype in Oracle 21cGoing Native: Leveraging the New JSON Native Datatype in Oracle 21c
Going Native: Leveraging the New JSON Native Datatype in Oracle 21c
 
UKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the DatabaseUKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the Database
 
Java-JSON-Jackson
Java-JSON-JacksonJava-JSON-Jackson
Java-JSON-Jackson
 
Starting with JSON Path Expressions in Oracle 12.1.0.2
Starting with JSON Path Expressions in Oracle 12.1.0.2Starting with JSON Path Expressions in Oracle 12.1.0.2
Starting with JSON Path Expressions in Oracle 12.1.0.2
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesBasics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examples
 
Store non-structured data in JSON column types and enhancements of JSON
Store non-structured data in JSON column types and enhancements of JSONStore non-structured data in JSON column types and enhancements of JSON
Store non-structured data in JSON column types and enhancements of JSON
 
JSON Processing and mule
JSON Processing and muleJSON Processing and mule
JSON Processing and mule
 
Json
JsonJson
Json
 
Json
JsonJson
Json
 
SQL gene in NoSQL
SQL gene in NoSQLSQL gene in NoSQL
SQL gene in NoSQL
 
java script json
java script jsonjava script json
java script json
 
Json
JsonJson
Json
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web Stack
 
Json
JsonJson
Json
 
Json at work overview and ecosystem-v2.0
Json at work   overview and ecosystem-v2.0Json at work   overview and ecosystem-v2.0
Json at work overview and ecosystem-v2.0
 
Json
JsonJson
Json
 

Recently uploaded

Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
SAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloudSAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloud
maazsz111
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
Data Hops
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 

Recently uploaded (20)

Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
SAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloudSAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloud
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 

Demystifying JSON in SQL Server

  • 1. Demystifying JSON in SQL Server BY KRISTIN FERRIER
  • 2. About Me – Kristin Ferrier  18+ Years in IT  Principal Consultant at Ferrier Solutions  Full stack web developer with specialty and passion for data  Twitter: @SQLEnergy  Techlahoma Slack: @EnergyDev  GitHub: @EnergyDev
  • 3. What we’ll cover  What is JSON?  Why use JSON?  JSON functionality in SQL Server (most of our time will be spent here)  Built-in functions  OPENJSON  FORJSON  More…
  • 5. What is JSON? JSON is data in the form of a JavaScript object But with stricter rules Like a string must be enclosed in quotation marks Above is a practical definition. Officially JSON is “a data exchange format that was created from a subset of the literal object notation in JavaScript”
  • 6. JSON Example [ { "QuoteID": 1, "Franchise": "Star Wars", "Character": "Yoda", "QuoteText": "Do. Or do not. There is no try." }, { "QuoteID": 2, "Franchise": "The Librarians", "Character": "Cassandra", "QuoteText": "Mathemagics. I like it.." } ]
  • 7. Why JSON?  JSON is a very popular data format used for exchanging data in modern web and mobile applications. Web / Mobile App Web API JSON JSON
  • 8. Why JSON over XML?  With respect to XML  JSON is more popular in modern development  JSON is lighter  JSON support in SQL Server is simpler
  • 10. JSON Functionality in SQL Server  Available starting with SQL Server 2016 and Azure SQL Database  Built-in functions  Validate JSON and Insert/Update/Delete data within JSON  OPENJSON  JSON => Tabular  FORJSON  Tabular => JSON  More…  Indexing, constraints, etc.
  • 11. JSON Built-in Functions  ISJSON – Validate that text is formatted as JSON ISJSON(@json)-> bit (0, 1, or null)  JSON_VALUE – Extract value from JSON text JSON_VALUE(@json, '$.FranchiseID') -> NVARCHAR(4000)  JSON_QUERY – Extract JSON fragment from JSON text JSON_QUERY(@json, '$.Characters') -> NVARCHAR(MAX)  JSON_MODIFY – Update, delete, or add properties in JSON text JSON_MODIFY(@json, '$.FranchiseProducer', 'Devlin') -> NVARCHAR(MAX)
  • 13. OPENJSON  Converts JSON to table data
  • 16. FOR JSON  Tabular data => JSON  FOR JSON AUTO  Defaults JSON structure  Some customization  Requires FROM clause  FOR JSON PATH  Customize overall JSON structure  Doesn’t require FROM clause
  • 19. Additional features  ISJSON constraints on JSON fields CONSTRAINT ensure_episodeJson CHECK (ISJSON(EpisodeJson) = 1)  Indexing ALTER TABLE dbo.Episode ADD vDirector AS JSON_VALUE(EpisodeJSON, '$.director') CREATE INDEX idx_episode_json_director ON dbo.Episode(vDirector)
  • 20. Q&A and Thank You Q&A Catch up with me later  Twitter @SQLEnergy  Techlahoma Slack @EnergyDev