ibireme / yyjson

The fastest JSON library in C
https://ibireme.github.io/yyjson/doc/doxygen/html/
MIT License
2.98k stars 261 forks source link

Diff two objects to create a patch #173

Open tim-lyon opened 1 week ago

tim-lyon commented 1 week ago

Is your feature request related to a problem? Please describe. I'd love to use yyjson on a project, but I need the ability to create patches from the diff of two JSON documents. Currently I would need to use nlohmann/json specifically for this feature. Thank you for your consideration 🙏

Describe the solution you'd like

yyjson_doc *patch = yyjson_diff(doc1, doc2);

Describe alternatives you've considered https://json.nlohmann.me/api/basic_json/diff/

ibireme commented 1 week ago

Since the objects and arrays are stored as linear data structures, creating an efficient diff algorithm could be quite complex or potentially slow. I'll look into it when I have more time.

tim-lyon commented 1 week ago

Thanks @ibireme For reference, the nlohmann implementation is only 130 LoC, and for my purpose at least, a similar implementation would be better than none. There are definitely opportunities for optimisation though.