JSON Support for SQL Server

Documentation › JsonNVarChar

JsonNVarChar(data, query, length) or JsonDataType QueryNVarChar(query, length)

Query a string value stored within a JSON string. Output will be truncated to the number of characters specified by the length parameter.

Example

JsonNVarChar(data, query, length)

JsonDataType QueryNVarChar(query, length)

declare @testData nvarchar(1000) set @testData = '{ "Numbers": "123456789" }' select dbo.JsonNVarChar(@testData, 'Numbers', 1) as [Test 1 Char], dbo.JsonNVarChar(@testData, 'Numbers', 5) as [Test 5 Chars], dbo.JsonNVarChar(@testData, 'Numbers', 10) as [Test 10 Chars]

Results

Test 1 Char Test 5 Chars Test 10 Chars
1 12345 123456789

JsonDataType QueryNVarChar(query, length)

declare @testData json set @testData = '{ "Numbers": "123456789" }' select @testData.QueryNVarChar('Numbers', 1) as [Test 1 Char], @testData.QueryNVarChar('Numbers', 5) as [Test 5 Chars], @testData.QueryNVarChar('Numbers', 10) as [Test 10 Chars]

Results

Test 1 Char Test 5 Chars Test 10 Chars
1 12345 123456789