In the CTP3 JSON example from AdventureWorks 2016, you can find a function that can clear an array of key: value pairs and create od array values:
DROP FUNCTION IF EXISTS dbo.ufnToRawJsonArray
GO
CREATE FUNCTION
[dbo].[ufnToRawJsonArray](@json nvarchar(max), @key nvarchar(400)) returns nvarchar(max)
AS BEGIN
declare @new nvarchar(max) = replace(@json, CONCAT('},{"', @key,'":'),',')
return '[' + substring(@new, 1 + (LEN(@key)+5), LEN(@new) -2 - (LEN(@key)+5)) + ']'
END
Just specify the result of the SELECT FOR JSON expression as the @json parameter and the name of the key you want to remove as the second parameter. Perhaps something like:
select dbo.ufnToRawJsonArray( (SELECT value FROM mytable for json path), 'value')
source
share