diff function
Computes an RFC 6902 JSON Patch that transforms from into to.
The diff is rooted at the document, so pointers are bare (e.g.
/agentStatus, /items/0). Only add / remove / replace operations
are emitted.
When the two documents differ at the root in a way that cannot be expressed
as member-level changes (e.g. an object becomes a list, or a primitive
changes), a single whole-document replace at path "" is returned.
Implementation
JsonPatch diff(Object? from, Object? to) {
final patch = <JsonPatchOperationMap>[];
_diffRecursive(from, to, '', patch);
return patch;
}