Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8067905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:29:07+00:00 2026-06-05T12:29:07+00:00

I have a pretty simple structure that looks something like this: var list =

  • 0

I have a pretty simple structure that looks something like this:

var list = new List<CategoryInTimeItem>
        {
            new CategoryInTimeItem { Name = "Food", Year = 2012, Month = 1, Amount = 100 },
            new CategoryInTimeItem { Name = "Food", Year = 2012, Month = 2, Amount = 110 },
            new CategoryInTimeItem { Name = "Food", Year = 2012, Month = 3, Amount = 130 },
            new CategoryInTimeItem { Name = "Food", Year = 2012, Month = 4, Amount = 130 },
            new CategoryInTimeItem { Name = "Transport", Year = 2012, Month = 1, Amount = 1000 },
            new CategoryInTimeItem { Name = "Transport", Year = 2012, Month = 2, Amount = 1101 },
            new CategoryInTimeItem { Name = "Transport", Year = 2012, Month = 3, Amount = 1301 },
            new CategoryInTimeItem { Name = "Transport", Year = 2012, Month = 4, Amount = 1301 }
        };

I want to reshape this structure so that when it get’s serialized to json the result should look like this, one array for each name:

[
[["2012-1", 100], ["2012-2", 110], ["2012-3", 130], ["2012-4", 130]],
[["2012-1", 1000], ["2012-2", 1101], ["2012-3", 1301], ["2012-4", 1301]]
]

My linq query looks like this:

   result.Values = 
                from d in list
                orderby d.Name , d.Year , d.Month
                group d by d.Name
                into grp
                select new[]
                {
                    grp.Select(y => new object[] {y.DateName, y.Amount})
                };

This almost works, however I get an extra “level” of arrays, so when serialized to json the result looks like this:

[
[[["2012-1", 100], ["2012-2", 110], ["2012-3", 130], ["2012-4", 130]]],
[[["2012-1", 1000], ["2012-2", 1101], ["2012-3", 1301], ["2012-4", 1301]]]
]

What am I doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:29:09+00:00Added an answer on June 5, 2026 at 12:29 pm

    You’ve almost been there, just instead of

    from d in list
    ...
    select new[]
    {
        grp.Select(y => new object[] {y.DateName, y.Amount})
    }
    

    simply:

    from d in list
    ...
    select grp.Select(y => new object[] {y.DateName, y.Amount}).ToList()
    

    You just added an unnecessary level of array at the end.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming I have a simple structure that looks like this: public class Range {
I have a pretty simple ASP.NET Web Form that looks a bit like the
I have a pretty simple problem. Basically I have an array called $list that
Basically I do have pretty simple database that I'd like to index with Lucene.
I'm pretty new to the Entity framework and I'm modelling this simple structure: With
I have a pretty simple Linq to XML query: var q = from c
I have a StaffLookup table which looks like this. UserSrn | UserName | ManagerSrn
I have a link being generated that looks like so: <a target=_blank title=Test href=file:///c:/test.xls>Test</a>
This question should be pretty simple. I have a php file in a directory
I have a rather simple SOLR structure, that hold three different fields: id, text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.