JSON Support for SQL Server

Documentation › JsonBit

JsonBit(data, query) or JsonDataType QueryBit(query)

Query a boolean value stored within a JSON string.

Example

JsonBit(data, query)

JsonDataType QueryBit(query)

declare @orderData nvarchar(1000) set @orderData = '{ "Name": "Bob Smith", "ItemCount": 12, "Total": 15.54, "Packed": true, "Shipped": false, "OrderDate": "2015-02-10 14:52:23", "Lines": [ { "Item": "Hat", "Quantity": 10, "UnitPrice": 1.11, "Total": 11.1 }, { "Item": "Scarf", "Quantity": 2, "UnitPrice": 2.22, "Total": 4.44 } ] }' select dbo.JsonBit(@orderData, 'Packed') as [Packed], dbo.JsonBit(@orderData, 'Shipped') as [Shipped]

Results

Packed Shipped
1 0

JsonDataType QueryBit(query)

declare @orderData json set @orderData = '{ "Name": "Bob Smith", "ItemCount": 12, "Total": 15.54, "Packed": true, "Shipped": false, "OrderDate": "2015-02-10 14:52:23", "Lines": [ { "Item": "Hat", "Quantity": 10, "UnitPrice": 1.11, "Total": 11.1 }, { "Item": "Scarf", "Quantity": 2, "UnitPrice": 2.22, "Total": 4.44 } ] }' select @orderData.QueryBit('Packed') as [Packed], @orderData.QueryBit('Shipped') as [Shipped]

Results

Packed Shipped
1 0