Skip to content

Instantly share code, notes, and snippets.

@Xor-el
Forked from bertwagner/LaxVersusStrict.sql
Created April 16, 2024 23:03
Show Gist options
  • Save Xor-el/be80ef62284d4b2188a64fc3d9bcdb74 to your computer and use it in GitHub Desktop.
Save Xor-el/be80ef62284d4b2188a64fc3d9bcdb74 to your computer and use it in GitHub Desktop.
SQL Server 2016 JSON's Lax versus Strict modes
-- Lax (default: function will return an error if invalid JSON path specified
SELECT JSON_VALUE('{ "Color" : "Red" }', '$.Shape') --lax is the default, so you don't need to be explicitly state it
-- Output: NULL
SELECT JSON_VALUE('{ "Color" : "Red" }', 'lax $.Shape')
-- Output: NULL
-- Strict: function will return an error if invalid JSON path specified
SELECT JSON_VALUE('{ "Color" : "Red" }', 'strict $.Shape')
-- Output: Property cannot be found on the specified JSON path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment