Skip to content

Instantly share code, notes, and snippets.

@bertwagner
Last active February 6, 2017 22:18
Show Gist options
  • Save bertwagner/cf3a16c3f08595f91d1d177a64265fed to your computer and use it in GitHub Desktop.
Save bertwagner/cf3a16c3f08595f91d1d177a64265fed to your computer and use it in GitHub Desktop.
SQL Server 2016 JSON's ISJSON() Function
SELECT ISJSON('{ "Color" : "Blue" }') -- Returns 1, valid
-- Output: 1
SELECT ISJSON('{ "Color" : Blue }') -- Returns 0, invalid, missing quotes
-- Output: 0
SELECT ISJSON('{ "Number" : 1 }') -- Returns 1, valid, numbers are allowed
-- Output: 1
SELECT ISJSON('{ "PurchaseDate" : "2015-08-18T00:00:00.000Z" }') -- Returns 1, valid, dates are just strings in ISO 8601 date format https://en.wikipedia.org/wiki/ISO_8601
-- Output: 1
SELECT ISJSON('{ "PurchaseDate" : 2015-08-18 }') -- Returns 0, invalid
-- Output: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment