stephenberry / glaze

Extremely fast, in memory, JSON and interface library for modern C++
MIT License
981 stars 102 forks source link

JSON diff & patch feature #769

Open edunad opened 4 months ago

edunad commented 4 months ago

Awesome lib so far :D, i'm currently migrating from nlohmann json and i was wondering if there are plans on implementing a diff & patch method? I tried looking around and merge seems to be the closest to patch, i'm currently implementing it on my lib, but would be nice to have glaze do it

Aka:

auto diff = glz::diff(json1, json2);

image

...later on..

auto patchedJSON = glz::patch(diff);

patchedJSON contains data kept the non-removed / replaced data from the prev json and added / removed data from json2, kinda like a migration.

Similar to https://json.nlohmann.me/api/basic_json/diff/

stephenberry commented 4 months ago

Glaze is focused on doing as much work at compile time as possible (for performance). Would a glz::diff on two separate structs, which produces a new object that we can read into to produce your patched JSON work? Or, does this diff need to occur at runtime for you?

In other words, do you know the layout (fields and types) of json1 and json2 at compile time? If so, we can make this diff reading/writing much more efficient.

edunad commented 4 months ago

Glaze is focused on doing as much work at compile time as possible (for performance). Would a glz::diff on two separate structs, which produces a new object that we can read into to produce your patched JSON work? Or, does this diff need to occur at runtime for you?

In other words, do you know the layout (fields and types) of json1 and json2 at compile time? If so, we can make this diff reading/writing much more efficient.

It would be great if both cases where supported, at the moment i use diff and patch for migrating user settings version (by using json_t), but i could make it so the app using the lib implements a settings struct 🤔, if it would allow json1 to have a structure and json2 to have a slightly different structure.

I also have plans of allowing lua scripting users to define their own settings (for modding), and that one i won't be able to predict the structure

stephenberry commented 4 months ago

Thanks for your additional explanation and thoughts. I like this idea and think it should be added, but it won't be a priority at the moment so I can't give you a date for the feature yet.

edunad commented 4 months ago

Thanks for your additional explanation and thoughts. I like this idea and think it should be added, but it won't be a priority at the moment so I can't give you a date for the feature yet.

No worries :D, am already implementing something on the side (not great but it works), thanks again for the amazing lib ^^