I have a DataTable like this: Sample DataTable
The JSON I require as output is in the below format:
{
"Column1": ["value1","value2"],
"Column2": ["value3"],
"Column3": ["value4","value5"]
},
{
"Column1": ["value1","value2"],
"Column2": ["value2","value3"],
"Column3": ["value4","value5"]
}
So basically I have a list of comma separated values in every row. It can be a single value as well. If multi value, I want the JSON to contain the array in the format as specified.
I am in total control of formatting the rows in the DataTable. I tried to build the format in the SQL Server query itself but as you know, when JsonConvert.SerializeObject(Datatable)
executes, it escapes the double quotes which is not what I want.
Please let me know how I can achieve this. I am using SQL Server 2008 and NewtonSoft Json on the C# side of it.
Edit -
The DataTable contains more than 10 rows and might add more later on. So I want to avoid custom logic on a particular column.