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 9196753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:55:11+00:00 2026-06-17T21:55:11+00:00

I have the following table: I’d like to execute a LINQ Query that serializes:

  • 0

I have the following table:

Table

I’d like to execute a LINQ Query that serializes:

JSON:

{
  "product-list": {
    "products": [
        {
          "P_Flavor": [
            "Berry",
            "Cedar",
            "Cherry",
            "Coffee"
          ],
          "P_Winery": [
            "Lyeth"
          ],
          "P_Body": [
            "Elegant",
            "Firm",
            "Firm Tannins",
            "Polished",
            "Supple",
            "Tannins"
          ],
          "P_Name": "A Red Blend",
          "P_DateReviewed": "08/31/95",
          "P_WineID": 34699,
          "P_Score": 5,
        }
    ]
  }
}

I would normally use JavaScriptSerializer to do this, however I would like to construct my own JSON payload.

IList<record_property> recList = (from c in entities.record_property
                                    select c).ToList();

var json = new JavaScriptSerializer().Serialize(recList);

What would be the best way to do this?

  • 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-17T21:55:12+00:00Added an answer on June 17, 2026 at 9:55 pm

    There may be a quicker/more concise way to do this, but I did it by combining a JavaScriptConverter with a helper type.

    The converter (simpler than it looks, inspired from here):

    private class RecordPropertyJavaScriptConverter : JavaScriptConverter
    {
        private static readonly Type[] _supportedTypes = new[]
        {
            typeof(record_group)
        };
    
        public override IEnumerable<Type> SupportedTypes
        {
            get { return _supportedTypes; }
        }
    
        public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            if (type == typeof(record_group))
            {
                record_group obj = new record_group();
    
                var kvp = dictionary.Single();
    
                obj.Key = kvp.Key;
                obj.Values = serializer.ConvertToType<IEnumerable<object>>(kvp.Value);
    
                return obj;
            }
    
            return null;
        }
    
        public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            var dataObj = obj as record_group;
            if (dataObj != null)
            {
                return new Dictionary<string, object>
                {
                    {dataObj.Key,  dataObj.Values}
                };
            }
            return new Dictionary<string, object>();
        }
    }
    

    The helper type:

    private class record_group
    {
        public string Key;
        public IEnumerable<object> Values;
    }
    

    The serialization code:

    var groups = recList.GroupBy(r => r.Key)
                        .Select(g => new record_group { Key = g.Key, Values = g.Select(r => r.Value) });
    
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    serializer.RegisterConverters(new [] {new RecordPropertyJavaScriptConverter()});
    string json = serializer.Serialize(groups);
    

    The output (with some tabs, newlines added by me):

    [{"P_Flavor":["Berry","Cedar","Cherry","Coffee"]},
     {"P_Winery":["Lyeth"]},
     {"P_Body":["Elegant","Firm","Firm Tannins","Polished","Supple","Tannins"]},
     {"P_Name":["A Red Blend"]},
     {"P_DateReviewed":["08/31/95"]},
     {"P_WineID":[34699]},
     {"P_Score":[5]}]
    

    Deserialization can then be done (using the same serializer instance from above) as follows:

    var deserialized = serializer.Deserialize<IEnumerable<record_group>>(json);
    var properties = deserialized.SelectMany(g => g.Values.Select(v => new record_property { Key = g.Key, Value = v }));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have following table like this <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
I have the following table: Order Product Price Quantity Description Order1 Product1 12 1
I have the following table that lists all awarded cups: Name: Cups Columns: Month,
I have following table in my database. I am trying to write a query
I have following table ID | Group | Type | Product 1 Dairy Milk
I am having issues with a sql query. I have following table (I simplified
I have the following table (let's say that its name is AnswerTable: QuestionID Value
I have following table structure, with many tables like this: data_1: +-------+--------+-------+ | views
I have following table structure there is column vid in that i want entry
I have following table setup: Order (ID) Product (ID) [where ProductID 1 and 2

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.