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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:12:00+00:00 2026-06-08T05:12:00+00:00

I have a couple JObjects that are being returned from different places but that

  • 0

I have a couple JObjects that are being returned from different places but that have all the same properties. I need to concatenate/merge this into one larger jObject. Is this possible and how would I go about doing it?

I want it to have all the same proerties as the individual objects. For instance.

jObject1 = { "data": [{"name": "foo","id": "1234" }]};
jObject2 = {"data": [{ "name": "foo2", "id": "5678" }]}; 

Resulting in something like this.

jobject3 = { "data": [{ "name": "foo", "id": "1234"}, { "name": "foo2", "id": "5678" }]};

I’m coding in C# and the only thing I have thought about doing so far is something like this which isn’t valid. Not really sure how to begin and can’t really anything.

jobject3 = jObject1.Concat(jObject2); 

I am trying to manually loop through each object and build a new object. I think I am close but keep getting an error when adding the second item (oAlldepartment.Add) saying “Can not add property to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.”.

dynamic dynObj = JsonConvert.DeserializeObject(people);
foreach (var item in dynObj.data)
{
string id = item.id;
string name = item.name;

department = getdepartment(id);

JObject oDepartment = new JObject();

try
{
    if (!String.IsNullOrEmpty(department))
        oDepartment = JObject.Parse(department);
}
catch (Exception ex)
{
}

JArray departmentArray = new JArray();

if (oDepartment != null)
{
    foreach (var x in oDepartment["data"].Children())
    {
        try
        {
            JObject departmentObject = new JObject();

            ((JObject)departmentObject).Add(new JProperty("name", x["name"]));
            ((JObject)departmentObject).Add(new JProperty("department", new JObject(new JProperty("name", x["department"]["name"]))));
            ((JObject)departmentObject).Add(new JProperty("hire_date", x["hire_date"]));
            ((JObject)departmentObject).Add(new JProperty("description", x["description"]));
            departmentArray.Add(departmentObject);

        }
        catch (Exception ex)
        {
        }

        ((JObject)x).Add(new JProperty("itemtype", "post"));
    }
    try
    {
        oAlldepartment.Add(new JProperty("", new JArray(departmentArray)));
    }
    catch (Exception ex)
    {
    }
}

}

Thanks,

Rhonda

  • 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-08T05:12:01+00:00Added an answer on June 8, 2026 at 5:12 am

    What I ended up doing was creating a class that defined the json I wanted to return and adding the json properties from each indivual object. The other benefit is my data returned by the method to the client is cleaner as I only have to worry about the properties I need instead of a huge json object with a bunch of properties that I don’t need.

    Rhonda

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

Sidebar

Related Questions

We have couple different web-apps that share the same db link. The hibernate layer
I have couple of forms with different ids but with same input names and
I have couple of dozen pieces of data that I need to save and
I got a couple of JNI functions that have to work on the same
I have couple of dll files that need to be registered/unregistered when a Windows
I have couple of questions regarding boost licensing, Is it that all the boost
I have couple of formulas and data coming from database. I want to refresh
I have couple resource DLLs that I currently load when application starts using following
ok I have couple of .NET classes that I want to use in VBA.
Here's the problem: I have couple of pages which gets its content from a

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.