Skip to content Skip to sidebar Skip to footer

Linq.js: Groupby(), Then Tojson()

I'm new to linq.js. I'd like to do a GroupBy(), which is then converted to JSON. However, I'm getting back a string array. var data = [ { 'Gender':'M' }, { 'Gender':'M' }, { 'Gende

Solution 1:

Turns out that I'd need to specify a key for each value (following the actual JSON format).

var grouped_dt = Enumerable.From(data).GroupBy("$.Gender", "key,e=>{name:key,y:e.Count()}", "").ToJSON();

Having done this, I'd also need to

var jsonData = $.parseJSON(grouped_dt);

to convert it into a JSON object for use.

Post a Comment for "Linq.js: Groupby(), Then Tojson()"