IsJsonValid
Checks the validity of a Json string
- Free Function
- SQL Server Compatibility: 2008, 2012, 2014, 2016, 2017
SELECT SQLHTTP.net.IsJsonValid( @Json )
Name | Type | Description |
---|---|---|
@Json | nvarchar(MAX) | Json string |
bit
0 = Json is NOT Valid
1 = Json IS Valid
Microsoft introduced the IsJson function starting with SQL Server 2016. This function can be used starting with SQL Server 2008.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
DECLARE @Json nvarchar(MAX) SET @Json = '{ "firstName": "John", "lastName": "Smith", "isAlive": true, "age": 25, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021-3100" }, "phoneNumbers": [ { "type": "home", "number": "212 555-1234" }, { "type": "office", "number": "646 555-4567" }, { "type": "mobile", "number": "123 456-7890" } ], "children": [], "spouse": null }' SELECT SQLHTTP.net.IsJsonValid(@Json) |
1 2 3 4 5 |
----- 1 |