I am trying to retrieve the data from our SQL server in a specific way, basically I have a column and it has a delimiter ','
and need to convert like an array using FOR JSON PATH
I have tried using FOR XML PATH and FOR JSON PATH, but I don't figure out how to overcome this query.
Besides that, I have other ways to resolve, mapping using Entity Framework + LINQ, I needed to fix or understand if it is possible in SQL SERVER.
it is my simple data without FOR JSON:
and this is what I am doing:
select * from #templateData FOR JSON PATH
-- result
[
{
"id": 1,
"name": "Full Stack Engineer",
"description": ".net developer with 20 year of experience,Scrum master,Hold bachelor degree "
},
{
"id": 2,
"name": "Web Developer",
"description": "web dev"
},
{
"id": 3,
"name": "Full Stack Engineer",
"description": "tested"
}
]
an this is what I am expecting (see the column description)
[
{
"id": 1,
"name": "Full Stack Engineer",
"description": [
{".net developer with 20 year of experience"},
{"Scrum master"},
{"Hold a bachelor degree"},
],
},
{
"id": 2,
"name": "Web Developer",
"description": "web dev"
},
{
"id": 3,
"name": "Full Stack Engineer",
"description": "tested"
}
]
I have tried using STRING_SPLIT
along with FOR JSON PATH
using CROSS_APPLY
however, without success.