JSON Support for SQL Server

Documentation › JsonNVarCharMax

JsonNVarCharMax(data, query) or JsonDataType QueryNVarCharMax(query)

Query a string value stored within a JSON string.

Example

JsonNVarCharMax(data, query)

JsonDataType QueryNVarCharMax(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.JsonNVarCharMax(@orderData, 'Lines[0].Item') as [Line 0 Item], dbo.JsonNVarCharMax(@orderData, 'Lines[1].Item') as [Line 1 Item], dbo.JsonNVarCharMax(@orderData, 'Name') as [Customer Name]

Results

Line 0 Item Line 1 Item Customer Name
Hat Scarf Bob Smith

JsonDataType QueryNVarCharMax(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.QueryNVarCharMax('Lines[0].Item') as [Line 0 Item], @orderData.QueryNVarCharMax('Lines[1].Item') as [Line 1 Item], @orderData.QueryNVarCharMax('Name') as [Customer Name]

Results

Line 0 Item Line 1 Item Customer Name
Hat Scarf Bob Smith