JSON Support for SQL Server

Documentation › JsonDecimal

JsonDecimal(data, query) or JsonDataType QueryDecimal(query)

Query a decimal value stored within a JSON string.

Example

JsonDecimal(data, query)

JsonDataType QueryDecimal(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.JsonDecimal(@orderData, 'Total') as [Order Total], dbo.JsonDecimal(@orderData, 'Lines[1].UnitPrice') as [Line 1 Unit Price], dbo.JsonDecimal(@orderData, 'Lines[1].Total') as [Line 1 Total]

Results

Order Total Line 1 Unit Price Line 1 Total
15.54 2.22 4.44

JsonDataType QueryDecimal(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.QueryDecimal('Total') as [Order Total], @orderData.QueryDecimal('Lines[1].UnitPrice') as [Line 1 Unit Price], @orderData.QueryDecimal('Lines[1].Total') as [Line 1 Total]

Results

Order Total Line 1 Unit Price Line 1 Total
15.54 2.22 4.44