Anwenden JSON Zusammenführen Patch (RFC 7396)
JSON Zusammenführen Patch applies ein partial JSON Objekt in aktualisieren ein Dokument — null Werte löschen Schlüssel, andere Werte ersetzen them. Simpler than JSON Patch.
- 1
JSON Merge Patch (RFC 7396) is a simple merge: take a patch object and apply it to the target. For each key in the patch: if the value is null, delete the key from the target; otherwise, set/replace the key. Nested objects are merged recursively. It is less expressive than JSON Patch but much simpler.
- 2 JSON-Formatierer →
Formatieren the original document and the merge patch. The patch is a plain JSON object — no special structure. Format both to verify valid JSON before merging.
- 3 JSON-Validator →
Validieren the merged result. The merge is straightforward: for each key in the patch, if null → delete from target, else → set in target. Validate the result to ensure the merge produced valid data.
- 4
Limitation: Merge Patch cannot add a null value (null means delete), cannot move or copy values, and cannot test before applying. For these operations, use JSON Patch (RFC 6902) instead. Merge Patch is ideal for simple partial updates from forms or API PATCH requests.
Häufige Fragen
- When to use Merge Patch vs JSON Patch?
- Use Merge Patch for simple partial updates (e.g., updating a few fields in a resource via PATCH /api/user). Use JSON Patch when you need to move/copy values, test conditions, or add null values. Merge Patch is simpler but less expressive.
- How are arrays handled in Merge Patch?
- Arrays are replaced entirely, not merged element-by-element. If the patch has {tags: ["a", "b"]}, the entire tags array is replaced. To modify individual array elements, use JSON Patch with array index paths.