JSON Patch: Operation-Based Updates

JSON Patch describes changes as an array of operations: add, remove, replace, move, copy, and test. Each operation specifies a JSON Pointer path and optionally a value. The test operation enables conditional patching — apply this change only if the current value matches expectations.

JSON Merge Patch: Simple Merging

JSON Merge Patch sends a JSON document that's merged into the target. Fields in the patch overwrite corresponding fields. Fields set to null are removed. Fields not mentioned are untouched. This handles the common case of updating a few scalar fields in a flat object elegantly.

Which to Choose

Use JSON Patch when you need to update nested structures, arrays, or conditional updates with test operations. Use JSON Merge Patch for simple flat objects where you're updating a few known fields. JSON Merge Patch fails for setting fields to null.

HTTP Method Convention

Partial updates use HTTP PATCH. The Content-Type for JSON Patch is 'application/json-patch+json'. For Merge Patch it's 'application/merge-patch+json'. Including the correct content type lets servers handle both formats on the same endpoint.

Key Takeaway

JSON Patch and JSON Merge Patch solve the partial update problem with different trade-offs. Merge Patch is simpler for flat objects; JSON Patch provides surgical precision for complex structures.