© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
8 replies
SWEETPONY

✅ how to merge two objects?

Sometimes ago I had this object:
public sealed record CreateFlightLegModel
{
    public string? Identity { get; init; }
    public LegIdentityArgument? LegIdentity { get; init; }
    public JsonDocument? LegData { get; set; }
}
public sealed record CreateFlightLegModel
{
    public string? Identity { get; init; }
    public LegIdentityArgument? LegIdentity { get; init; }
    public JsonDocument? LegData { get; set; }
}


LegData
LegData
used in method for merging and for example we can do this:
var firstLeg =
    JsonDocument.Parse(@"{
    ""fuel"":
    {
      ""fuel_invoice_1"": ""1"",
      ""fuel_invoice_2"": ""2"",
      ""fuel_invoice_3"": ""3""
    }
}");
    JsonDocument.Parse(@"{
    ""fuel"":
    {
      ""fuel_invoice_1"": ""1"",
      ""fuel_invoice_2"": ""2"",
      ""fuel_invoice_3"": ""3""
    }
}");


var secondLeg=
    JsonDocument.Parse(@"{
    ""fuel"":
    {
      ""fuel_invoice_2"": null,
      ""fuel_invoice_3"": null
    }
}");
    JsonDocument.Parse(@"{
    ""fuel"":
    {
      ""fuel_invoice_2"": null,
      ""fuel_invoice_3"": null
    }
}");


and the output will be:
{
    ""fuel"":
    {
      ""fuel_invoice_1"": ""1"",
      ""fuel_invoice_2"": null,
      ""fuel_invoice_3"": null
    }
}
{
    ""fuel"":
    {
      ""fuel_invoice_1"": ""1"",
      ""fuel_invoice_2"": null,
      ""fuel_invoice_3"": null
    }
}


then we decided move from JsonDocument to model and this merge doesn't work anymore
in case I pasted earlier output will be:
""fuel"":
    {
      ""fuel_invoice_1"": null,
      ""fuel_invoice_2"": null,
      ""fuel_invoice_3"": null
    }
""fuel"":
    {
      ""fuel_invoice_1"": null,
      ""fuel_invoice_2"": null,
      ""fuel_invoice_3"": null
    }


can someone understand me what to do?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Making an azure Function to merge two JSON objects
C#CC# / help
4y ago
Merge objects game
C#CC# / help
2y ago
Merge two separate databases
C#CC# / help
3y ago
❔ how to merge two projects together and interact with them in visual studio
C#CC# / help
3y ago