I thought the following would be a pretty common task and assumed there would be an easy solution for it, but i can\'t find one.
If I have a datatable in the followi
Using JSON.NET (Newtonsoft.Json.Linq
)
var obj = new JObject(
dataTable.Rows.Cast()
.Select(r => new JProperty(r["ID"].ToString(),
new JObject(
new JProperty("Name", r["Name"].ToString()),
new JProperty("Active", r["Active"].ToString())
)
))
);
// Convert the JObject to a JSON string
var json = obj.ToString();