By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Create table #cust(a varchar(10),b varchar(10),c varchar(10))
truncate table #cust
Insert into #cust values
('Rock', 'paper','scissors'),
('Rock', 'paper','scissors'),
('Rock', 'paper','scissors')
DECLARE @nl varchar(2) = char(13), @tb varchar(2) = ' ' , @Json nvarchar(MAX) = (Select a,b,c from #CUST FOR JSON AUTO)
Select @Json = Replace(@Json, '[{','[' + @nl + '{')
Select @Json = Replace(@Json, '{','{' + @nl)
Select @Json = Replace(@Json, '","','",' + @nl + '"' )
Select @Json = Replace(@Json, '"},{','"' + @nl + '},' + @nl + @nl + '{' )
Select @Json = Replace(@Json, '"}]','"' + @nl + '}' + @nl + ']' + @nl + @nl)
Select @Json = Replace(@Json, @nl + '"', @nl + @tb + '"')
Select @Json as FormattedJSON
FormattedJSON |
---|
[ { "a":"Rock", "b":"paper", "c":"scissors" }, { "a":"Rock", "b":"paper", "c":"scissors" }, { "a":"Rock", "b":"paper", "c":"scissors" } ] |