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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:26:27+00:00 2026-05-18T00:26:27+00:00

I have JSON data like shown below. I only included column names once to

  • 0

I have JSON data like shown below. I only included column names once to save data size. Please let me know how do I convert this to C# object list.

// JSON
{
    "COLUMNS": [
        "id", "country","lastname", "firstname", "email", "category"
    ], 
    "DATA": [
        [43, "USA", "jon", "doe", "doe@gmail.com", "HR"], 
        [44, "JAPAN", "tanaka", "yidi", "yidi@aol.com", "IT"]
    ]
}

// .NET
Employee emp = JsonConvert.DeserializeObject<Employee>(jsonData);  

I should be able to access object properties like emp.lastname.

Also, as the title indicates, I am using the JsonConvert class in the Json.NET library.

  • 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-05-18T00:26:28+00:00Added an answer on May 18, 2026 at 12:26 am

    You won’t be able to use the JsonConvert class directly, as it expects all properties to have a name/mapping, and isn’t able to ascertain it because you are essentially using a custom format.

    What you need to do is create a class that has the columns and the data and serialize into that, like so:

    class CustomData
    {
        public string Columns { get; set; }
        public object[,] Data { get; set; }
    }
    

    JsonConvert should be able to convert your data into this structure in .NET.

    From there, it becomes more of a .NET issue, in that you have to get the names of the columns and data. You should be able to use LINQ to help with pairing the two and then use reflection to populate your item:

    // The custom data structure, deserialized from JSON.
    CustomData data = ...;
    
    // The type of Employee.
    Type type = typeof(Employee);
    
    // Create a map of the property info to the ordinal in the
    // Columns.
    IDictionary<int, PropertyInfo> propertyMap = data.Columns.
        Select((p, i) => 
            new { Index = i, PropertyInfo = type.GetProperty(p) }).
        ToDictionary(p => p.Index, p => p.PropertyInfo);
    
    // Cycle through the rows in the data.
    var query =
        // Cycle through all of the rows.
        from row in Enumerable.Range(0, data.Data.GetLength(0))
    
        // Create the instance.
        let instance = new Employee()
    
        // For each column in the row.
        from column in Enumerable.Range(0, data.Data.GetLength(1))
    
        // Lookup the property info.
        let propertyInfo = propertyMap[column]
    
        // Select the instance, the property, and the value.
        select { 
            // This is used for grouping purposes, since
            // you can't guarantee that the type you are serializing
            // to will have natural identity properties and
            // you know the row corresponds to one singular instance.
            Row = row,
            Instance = instance, 
            PropertyInfo = propertyInfo,
            Value = data.Data[row, column]
        };
    
    // Iterate through the items, setting the instance values.
    foreach (var propertyAndData in query)
    {
        // Set the property value on the instance.
        propertyAndData.PropertyInfo.
            SetValue(propertyAndData.Instance, Value, null);
    }
    
    // Group by the row and get the first item in each sequence.
    IEnumerable<Employee> employees =
        from item in query
        groupby item by item.Row into g
        select g.First();
    

    The only caveat for the above; if you are using a value type, then you will not populate the same instance as you iterate through this. In order to handle value types, you have to unwind the LINQ query and iterate through each row and column using for loops, creating the new instance on each new row and then using Reflection as above to populate the properties.

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

Sidebar

Related Questions

I have a web service that queries data from this json file, but I
I have the following javascript: $.ajax({ type: "POST", dataType: "json", url: "/Home/Submit", data: {
I have a JSON result that contains numerous records. I'd like to show the
So, I have a json file and I want to get the names of
I have a web service that returns a raw string of JSON data (sample
I have some problems getting the custom formated JSON data into a dijit.form.FilteringSelect. It
I have a large amount of nested data formatted in JSON . I would
I have a JSON array with ActiveRecord objects. These objects can be reconstructed using
I have a JSON as follows { columns : [RULE_ID,COUNTRY_CODE], RULE_ID : [1,2,3,7,9,101,102,103,104,105,106,4,5,100,30], COUNTRY_CODE
I have one JSON that is coming in a string format. I need to

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.