the following is the sample data which is an input
if object_id('tempdb.dbo.#store_data') is not null
drop table #store_data
create table #store_data ([key] nvarchar(max),[value] nvarchar(max),storeid varchar(100)
)
INSERT INTO #store_data VALUES ('sid','1','1')
INSERT INTO #store_data VALUES ('bid','3','1');
INSERT INTO #store_data VALUES ('time','2019-01-01','1');
INSERT INTO #store_data VALUES ('que','apple','1');
INSERT INTO #store_data VALUES ('sid','2','2');
INSERT INTO #store_data VALUES ('bid','5','2');
INSERT INTO #store_data VALUES ('hrs','6','2');
INSERT INTO #store_data VALUES ('dat','pine','2');
select * from #store_data
the following is the result required
[{
"sid"="1",
"bid"="3",
"time"="2019-01-01"
"que"="apple"},
{"sid"="2",
"bid"="5",
"hrs"="6",
"dat"="pine"
}]
the following is the query which i have tried
select [key],[value] from #store_data for json path
expected results were not achieved.

ORDER BYthis can work hundred times, pass all internal tests, but will return rubbish in production. It is nothing then random ifbid=3appears in the first or in the second JSON object.SELECTwithout an outermostORDER BYcan return in any random sort order. If you want to persist the sort order, the easiest is to add anIDENTITYcolumn.