Convert IEnumerable<dynamic> to JsonArray
- by Burt
I am selecting an IEnumerable<dynamic> from the database using Rob Conery's Massive framework. The structure comes back in a flat format Poco C#. I need to transform the data and output it to a Json array (format show at bottom).
I thought I could do the transform using linq (my unsuccessful effort is shown below):
using System.Collections.Generic;
using System.Json;
using System.Linq;
using System.ServiceModel.Web;
....
IEnumerable<dynamic> list = _repository.All("", "", 0).ToList();
JsonArray returnValue = from item in list
select new JsonObject()
{
Name = item.Test,
Data = new dyamic(){...}...
};
Here is the Json I am trying to generate:
[
{
"id": "1",
"title": "Data Title",
"data": [
{
"column1 name": "the value",
"column2 name": "the value",
"column3 name": "",
"column4 name": "the value"
}
]
},
{
"id": "2",
"title": "Data Title",
"data": [
{
"column1 name": "the value",
"column2 name": "the value",
"column3 name": "the value",
"column4 name": "the value"
}
]
}
]