JavaScript Object Notation (JSON) Patch
This is implementation of rfc6902.
JSON Patch defines a JSON document structure for expressing a sequence of operations to apply to a JavaScript Object Notation (JSON) document.
library functionality:
- generate diff between two documents
- patch in place document using generated patch
Json document format accepted: JSONValue
Interface
alias JsonItem = JSONValue;
// diff part
DiffOperation[] diff(const ref JsonItem source, const ref JsonItem target,
const string path = "");
JsonItem toJson(DiffOperation[] d);
// patch part
bool patchInPlace(ref JsonItem document, ref const JsonItem patch);
Usage
import vision.json.patch.commons;
import vision.json.patch.diff;
import vision.json.patch.patch;
JsonItem source = ...;
JsonItem target = ...;
auto patch = diff(source, target).toJson;
auto patched = source;
patched.patchInPlace(patch);
assert(patched == target)