Skip to content

Instantly share code, notes, and snippets.

@bertwagner
Last active February 6, 2017 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bertwagner/509e826d0306b74be33d94a034472f13 to your computer and use it in GitHub Desktop.
Save bertwagner/509e826d0306b74be33d94a034472f13 to your computer and use it in GitHub Desktop.
SQL Server 2016 JSON's direct JSON string creation
-- The most primative way of creating JSON in SQL. We don't want to have to do this
DECLARE @garage nvarchar(100) = '{ "Cars" : [{ "Make" : "Volkswagen"}, { "Make" : "Subaru"}] }'
-- But it works!
SELECT @garage
-- Output: { "Cars" : [{ "Make" : "Volkswagen"}, { "Make" : "Subaru"}] }
-- And with our SQL 2016 ISJSON() function we can check that the JSON string is valid
SELECT ISJSON(@garage)
-- Output: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment