←back to thread

JSON Patch

(zuplo.com)
299 points DataOverload | 1 comments | | HN request time: 0.204s | source
Show context
patwolf ◴[] No.41882874[source]
I'm working on a project using CRDTs (Yjs) to generate efficient diffs for documents. I could probably use JSON Patch, but I worry about relying on something like fast-json-patch to automatically generate patches by diffing JSON documents.

If I have json like

[{"name": "Bob", age: 22}, {"name": "Sally", age: 40}]

and then I delete the "Sally" element and add "Jenny" with the same age, I end up with

[{"name": "Bob", age: 22"}, {"name": "Jenny", age: 40}]

However, the patch would potentially look like I changed the name of "Sally" to "Jenny", when in reality I deleted and added a new element. If I'm submitting this to a server and need to reconcile it with a database, the server cares about the specifics of how the JSON was manipulated.

I'd end up needing some sort of container object (like Yjs provides) that can track the individual changes and generate a correct patch.

replies(3): >>41882943 #>>41883049 #>>41885794 #
1. msikora ◴[] No.41882943[source]
Just add some unique IDs to your records.