Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
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
Authors (3):
Arrow left icon
Dejan Sarka Dejan Sarka
Author Profile Icon Dejan Sarka
Dejan Sarka
Miloš Radivojević Miloš Radivojević
Author Profile Icon Miloš Radivojević
Miloš Radivojević
William Durkin William Durkin
Author Profile Icon William Durkin
William Durkin
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

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 18. Other Books You May Enjoy

Validating JSON data


To validate JSON, you can use the ISJSON function. This is a scalar function and checks whether the input string is valid JSON data. The function has one input argument:

  • string: This is an expression of any string data type, except text and ntext.

The return type of the function is int, but only three values are possible:

  • 1 , if the input string is JSON conforming
  • 0 , if the input string is not valid JSON data
  • NULL , if the input expression is NULL

The following statement checks whether the input variable is JSON valid:

SELECT  
  ISJSON ('test'),  
  ISJSON (''),  
  ISJSON ('{}'),  
  ISJSON ('{"a"}'),  
  ISJSON ('{"a":1}'), 
  ISJSON ('{"a":1"}');

Here is the output:

------ ------ ------ ------ ------ ------0      0      1      0      1      0

ISJSON does not check the uniqueness of keys at the same level. Therefore, this JSON data is valid:

SELECT ISJSON ('{"id":1, "id":"a"}') AS is_json; 

It returns:

is_json-----------1

Since there is no JSON data type and data must be stored...

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 €18.99/month. Cancel anytime