Hi,
I am using SQL 2017 JSON features but little stuck in this. I am sorry if its a noobie question. You can see the output. I am not getting correct output when using case in JSON_QUERY.
create table #Color(ColorNameList varchar(max)) insert into #Color(ColorNameList) values ('["Marine Green","Lime"]'), ('ALL') Select * from #Color Select ISJSON(ColorNameList) IsJsonData,ColorNameList from #Color Select ISJSON(ColorNameList) IsJsonData,case when ISJSON(ColorNameList) = 1 then JSON_QUERY(ColorNameList) else ColorNameList end ColorNameList from #Color Select ISJSON(ColorNameList) IsJsonData,case when ISJSON(ColorNameList) = 1 then JSON_QUERY(ColorNameList) else ColorNameList end ColorNameList from #Color for json auto --Like this. Select top 1 ISJSON(ColorNameList) IsJsonData,JSON_QUERY(ColorNameList) ColorNameList from #Color for json auto --Output is [{"IsJsonData":1,"ColorNameList":"[\"Marine Green\",\"Lime\"]"},{"IsJsonData":0,"ColorNameList":"ALL"}] --should be [{"IsJsonData":1,"ColorNameList":["Marine Green","Lime"]},{"IsJsonData":0,"ColorNameList":"ALL"}] drop table #Color