RFC 7386, Faithfully
Your extension keeps a JSON document per record — a product configuration synced with an e-commerce platform — and the platform sends changes as application/merge-patch+json bodies, the format defined by RFC 7386. The previous implementation "applied" a patch by copying every property it could read, defaults for the rest; the first patch that tried to remove a property put the default back instead, and nobody noticed for a month. You are writing the real thing: a merge-patch engine that passes the RFC's own test-case appendix, row by row.
Requirements
Create a codeunit named "Json Merge Patch" with exactly this public procedure:
procedure ApplyMergePatch(Target: JsonToken; Patch: JsonToken): JsonTokenBoth parameters can hold any JSON value — an object, an array, a string, a number, a boolean or null — and so can the returned token. The semantics are RFC 7386, nothing more and nothing less:
- If the patch is not a JSON object (an array, a string, a number, a boolean or null), the result is the patch itself: it replaces the whole target, no matter what the target was.
- If the patch is a JSON object, the result is an object built from the target: when the target is not an object, its contents are discarded and you start from an empty object.
- Each member of the patch object is then applied by name. A member whose value is
nulldeletes the member with that name from the result — and if no such member exists, the null does nothing at all; a null is never stored.
Solve it with Pro
You’re reading the opening of the statement. Pro unlocks the whole problem:
- The full statement
- Starter code in the browser editor
- 18 grading tests, run on Business Central 28.5
- 3 hints
- The reference solution
Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.
Already on Pro? Sign in