The JSON patch specification used by MarkLogic PATCH API is remarkably similar to the JSON-Path standard (RFC 6902) but not exactly the same. For example, to add a node to the following document:
{
"parent": {
"child1": "c1-value",
"child2": "c2-value"
}
}
The MarkLogic patch:
{
"insert": {
"context": "/parent",
"position": "last-child",
"content": { "child3": "c3-value" }
}
}
The JSON-Patch standard:
{
"op": "add",
"path": "/parent/child3",
"value": "c3-value"
}
Is there a way to automatically translate JSON-Patch into MarkLogic Patch? My thought is to leverage libraries such as json-patch-gen
to automatically generate JSON-Patch operations and convert them into MarkLogic Patches to update documents in MarkLogic.
Alternatively, is there a JavaScript library available to automatically generate MarkLogic patches by DIFF-ing two JavaScript objects?