JSON Patch, Merge Patch and JSON Pointer Workbench
Test a JSON Patch against a real document step by step, generate a patch from two versions, try a merge patch and check pointer paths before they reach your API.
Hufanya kazi kwenye kivinjari chako. Faili zako hazitoki kamwe kwenye kifaa. Tazama jinsi ya kuthibitisha
…
Jinsi ya kufanya
- 1Paste the source
Put the current document in Source document, or tap Sample.
- 2Pick a mode
Tap Apply JSON Patch, Apply Merge Patch, Create patch or Pointer tester.
- 3Add the patch or target
Paste the patch array, the merge object, or the target document.
- 4Step through
Tap steps, or use Prev and Next, to see the document after each operation.
- 5Invert or reuse
Press Invert patch for a rollback, or Open in Apply to test a generated patch.
- 6Export
Copy the result or download the patched document or the generated patch as JSON.
Kuhusu zana hii
Many APIs accept partial updates instead of whole documents. Kubernetes, Azure, ASP.NET Core and many REST services take an HTTP PATCH with a JSON Patch body, a list of operations such as add, remove, replace, move, copy and test, each addressed by a JSON Pointer like /spec/replicas. Others accept a JSON Merge Patch, a plain object where every member replaces the target member and null deletes it. Both look simple, yet small mistakes are common: a pointer that misses the leading slash, a key containing a slash that was not escaped, an array index one past the end, a test that fails on a type difference, or a merge patch that was expected to append to an array but replaced it. This workbench lets you see what a patch really does before you send it. It applies the operations in order exactly as the standard describes, shows the document after every step and stops at the first failing operation without changing anything, which mirrors the all-or-nothing rule servers follow.
Four modes
Apply JSON Patch runs an RFC 6902 array against your source document. The step list marks every operation with a tick or a cross and the reason for a failure, for example that index 4 is out of range or that a test found 1.4.1 instead of 1.4.0. Tap any step to see the document as it was right after it. Apply Merge Patch follows RFC 7386: objects are merged recursively, null removes a member and any non-object value, including an array, replaces the target as a whole. Create patch compares the source with a target document and writes the operations that turn one into the other; it then applies them to the source and confirms that the result equals the target. Pointer tester resolves a JSON Pointer and lists every pointer in the document, so you can tap one instead of typing it.
Inverting a patch
After a successful run, Invert patch builds the operations that undo it, recording the old value of everything that was replaced or removed. The result becomes the new source and the inverse becomes the new patch, so you can check that applying it returns the original. This is useful for writing rollback steps for configuration changes.
Limits
Created JSON Patch documents compare arrays by position, so inserting one item near the start of a long array produces several replace operations rather than a single add; the result is still correct but not minimal. A merge patch cannot set a member to null, and the tool warns when the target contains null values. Very large documents of tens of megabytes work but the step view keeps a copy per step, so it is not meant for patches with thousands of operations. The tool does not send requests to your API.
Mfano uliotatuliwa
A platform engineer has a service config with version 1.4.0, two servers and an owner object. The patch tests that version is 1.4.0, replaces it with 1.5.0, adds ap-1 to the end of servers with the pointer /servers/-, removes /features/beta, moves /owner/email to /contact and copies /owner/team to /features/owner. All six steps get a tick and the final document has three servers. Changing the test value to 1.3.9 makes step 1 fail with found 1.4.0, and the panel confirms nothing was applied. In Create patch mode, comparing the source with a version 2.0.0 target gives 5 operations and the line verified: applying it to the source gives the target exactly.
Kwa ufupi
- Kategoria: Wasanidi na data
- Hufanya kazi kwenye kivinjari, bila usajili, bila kupakia.
- Taarifa unazoingiza hubaki kwenye kifaa chako.
- Inapatikana kwa Kiingereza.
- Maudhui yalikaguliwa mwisho:
- Chanzo rasmi: IETF RFC 6902 (JSON Patch), RFC 7386 (JSON Merge Patch) and RFC 6901 (JSON Pointer)
Maswali yanayoulizwa mara kwa mara
What is the difference between JSON Patch and Merge Patch?
JSON Patch is a list of explicit operations with pointers and can do anything, including inserting into arrays and testing values. Merge Patch is a partial document that is merged in; it is easier to write but cannot append to arrays or set null.
How do I point at a key that contains a slash?
Escape ~ as ~0 and / as ~1. The key a/b is written /a~1b. The pointer tester shows the escaped form of every key in your document.
What does the - in /servers/- mean?
It means the position after the last element, so add with that path appends to the array. It is only valid for add, and for the target of move and copy.
Why did my whole patch fail when only one operation was wrong?
RFC 6902 says a patch is applied atomically: if any operation fails, the document must stay unchanged. The step list shows which operation stopped it.
Can it generate the smallest possible patch?
It generates a correct patch and verifies it, but arrays are compared item by item by position, so it is not always the shortest. Review long array changes by hand if size matters.
Is anything uploaded?
No. Documents and patches stay in your browser; the last state is saved in local storage so a reload keeps your work.
