© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
82 replies
malkav

Can't get items to be added to update

I can't seem to get the "update" List filled..
I have this Json data https://hastebin.com/bazadowese.json
What I am trying to do, is everything that is not in the targetJson should be added to the "inject" list, and the items that are in the targetJson should be checked against the items in the sourceJson, if they are not in there, done. If they are check if they have differences, if they have differences add that item to the "update" list.

Currently it just adds everything from the sourceJson into the "inject" list and doesn't do squat for the update list.

Here's the function:
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
LookupInputs data = JsonConvert.DeserializeObject<LookupInputs>(requestBody);
if (data == null)
    return new BadRequestObjectResult("There was no data provided, or the data was not formatted properly");

Dictionary<string, List<Dictionary<string, JToken>>> result = new()
{
    { "inject", new() },
    { "update", new() }
};

if (data.TargetJson.Count == 0)
{
    result["inject"] = (from item in data.SourceJson select item).ToList();
}
else
{
    result["inject"] = (from source in data.SourceJson
        from target in data.TargetJson
        where source[data.CommonIdentifier] != target[data.CommonIdentifier] && !source.DictEquals(target)
        select source).ToList();

    result["update"] = (from source in data.SourceJson
        from target in data.TargetJson
        where source[data.CommonIdentifier] == target[data.CommonIdentifier] // && !source.DictEquals(target)
        select target).ToList();
}

return new OkObjectResult(results);
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
LookupInputs data = JsonConvert.DeserializeObject<LookupInputs>(requestBody);
if (data == null)
    return new BadRequestObjectResult("There was no data provided, or the data was not formatted properly");

Dictionary<string, List<Dictionary<string, JToken>>> result = new()
{
    { "inject", new() },
    { "update", new() }
};

if (data.TargetJson.Count == 0)
{
    result["inject"] = (from item in data.SourceJson select item).ToList();
}
else
{
    result["inject"] = (from source in data.SourceJson
        from target in data.TargetJson
        where source[data.CommonIdentifier] != target[data.CommonIdentifier] && !source.DictEquals(target)
        select source).ToList();

    result["update"] = (from source in data.SourceJson
        from target in data.TargetJson
        where source[data.CommonIdentifier] == target[data.CommonIdentifier] // && !source.DictEquals(target)
        select target).ToList();
}

return new OkObjectResult(results);

this is the current result: https://hastebin.com/buxaroneda.json
the result I'm expecting is that the item "BookID": "6" is left out of the "inject" list, and added to the "update" list
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements
Next page

Similar Threads

✅ WPF trees with some items that can't be selected
C#CC# / help
3y ago
✅ Can't get `InternalsVisibleTo` to work
C#CC# / help
4y ago
❔ can't get cloned repo to build
C#CC# / help
3y ago