JSON Support for SQL Server

Documentation › JsonFloat

JsonFloat(data, query) or JsonDataType QueryFloat(query)

Query a 64-bit floating-point value stored within a JSON string.

Example

JsonFloat(data, query)

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

Results

Order Total Line 0 Unit Price Line 0 Total
15.54 1.11 11.1

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

Results

Order Total Line 0 Unit Price Line 0 Total
15.54 1.11 11.1