Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
SQL Server 2017 Developer???s Guide

You're reading from   SQL Server 2017 Developer???s Guide A professional guide to designing and developing enterprise database applications

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher Packt
ISBN-13 9781788476195
Length 816 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (25) Chapters Close

Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
1. Introduction to SQL Server 2017 FREE CHAPTER 2. Review of SQL Server Features for Developers 3. SQL Server Tools 4. Transact-SQL and Database Engine Enhancements 5. JSON Support in SQL Server 6. Stretch Database 7. Temporal Tables 8. Tightening Security 9. Query Store 10. Columnstore Indexes 11. Introducing SQL Server In-Memory OLTP 12. In-Memory OLTP Improvements in SQL Server 2017 13. Supporting R in SQL Server 14. Data Exploration and Predictive Modeling with R 15. Introducing Python 16. Graph Database 17. Containers and SQL on Linux 1. Other Books You May Enjoy Index

Modifying JSON data


You might sometimes need to update only a part of JSON data. In SQL Server 2016, you can modify JSON data using the JSON_MODIFY function. It allows you to:

  • Update the value of an existing property
  • Add a new element to an existing array
  • Insert a new property and its value
  • Delete a property based on a combination of modes and provided values

The function accepts three mandatory input arguments:

  • Expression: This is a variable or column name containing JSON text.
  • Path: This is the JSON path expression with an optional modifier append.
  • new_value: This is the new value for the property specified in the path expression.

The JSON_MODIFY function returns the updated JSON string. In the next subsections, you will see this function in action.

Adding a new JSON property

In the following code example, you add a new property named IsVinyl with the value true:

DECLARE @json NVARCHAR(MAX) = N'{ 
"Album":"Wish You Were Here", 
"Year":1975 
}'; 
PRINT JSON_MODIFY(@json, '$.IsVinyl', CAST(1 AS BIT...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images