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
Ad

More Related Content

Similar to Demystifying JSON in SQL Server (20)

JSON-SQLServer2016.pptx dgsdgdsgdsgdsgsdgdsgdsg
JSON-SQLServer2016.pptx dgsdgdsgdsgdsgsdgdsgdsgJSON-SQLServer2016.pptx dgsdgdsgdsgdsgsdgdsgdsg
JSON-SQLServer2016.pptx dgsdgdsgdsgdsgsdgdsgdsg
zmulani8
 
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 Presentation.pptx JSON Presentation.pptx
JSON Presentation.pptx JSON Presentation.pptxJSON Presentation.pptx JSON Presentation.pptx
JSON Presentation.pptx JSON Presentation.pptx
trwdcn
 
JSON Processing and mule
JSON Processing and muleJSON Processing and mule
JSON Processing and mule
Santhosh Gowd
 
Json
JsonJson
Json
baabtra.com - No. 1 supplier of quality freshers
 
Json
JsonJson
Json
Anderson Oliveira
 
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
Json
Anand Kumar Rajana
 
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
Prabhat gangwar
 
JSON-SQLServer2016.pptx dgsdgdsgdsgdsgsdgdsgdsg
JSON-SQLServer2016.pptx dgsdgdsgdsgdsgsdgdsgdsgJSON-SQLServer2016.pptx dgsdgdsgdsgdsgsdgdsgdsg
JSON-SQLServer2016.pptx dgsdgdsgdsgdsgsdgdsgdsg
zmulani8
 
Native JSON Support in SQL2016
Native JSON Support in SQL2016Native JSON Support in SQL2016
Native JSON Support in SQL2016
Ivo Andreev
 
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
 
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 Presentation.pptx JSON Presentation.pptx
JSON Presentation.pptx JSON Presentation.pptxJSON Presentation.pptx JSON Presentation.pptx
JSON Presentation.pptx JSON Presentation.pptx
trwdcn
 
JSON Processing and mule
JSON Processing and muleJSON Processing and mule
JSON Processing and mule
Santhosh Gowd
 
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
 

Recently uploaded (20)

Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptxWebinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
MSP360
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
The Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdfThe Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdf
Precisely
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and MLGyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
Gyrus AI
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptxWebinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
MSP360
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
The Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdfThe Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdf
Precisely
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and MLGyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
Gyrus AI
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Ad

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
  翻译: