JSON.Patch
implements RFC 6902 JSON Patch, a JSON array of operation objects describing a sequence of changes to a document.
apply
(Fn [(Ref JSON a), (Ref JSON b)] (Result JSON JSON.PatchError))
(apply doc patch)
applies an RFC 6902 JSON Patch to doc, returning a
(Result JSON PatchError). Operations are applied in order and the patch is
atomic: on failure doc is untouched and the error names the operation index.
(JSON.Patch.apply &doc &patch)
diff
(Fn [(Ref JSON a), (Ref JSON a)] JSON)
(diff a b)
builds an RFC 6902 patch taking a to b, the inverse of
apply: applying the result to a returns b for any two documents.
Objects are compared member by member, emitting add for a key only in b,
remove for a key only in a, and nothing for members the two share. Arrays
are compared element by element, growing with add and shrinking with
remove. Everything else that differs becomes a replace, so two documents
of different kinds diff to one replace of the whole document.
(JSON.Patch.apply &a &(JSON.Patch.diff &a &b))