Intermediate LevelREST APIs & Web Services
Compare JSON Patch (RFC 6902) vs JSON Merge Patch (RFC 7396) for REST updates.
❓ Interview Prompt: Compare `PATCH` standards: JSON Patch (RFC 6902 array of atomic operations: `add`, `remove`, `replace`) vs JSON Merge Patch (RFC 7396 partial JSON object override).
RFC standards for executing partial updates via HTTP 'PATCH':
1
JSON Merge Patch (RFC 7396): 'Content-Type: application/merge-patch+json'.
•
Client sends partial JSON object overriding fields. Limitation: Cannot easily set a field to 'null' or remove an array element.
2
JSON Patch (RFC 6902): 'Content-Type: application/json-patch+json'.
•
Client sends an array of explicit atomic operations ('add', 'remove', 'replace', 'copy', 'move', 'test'). Allows precise manipulation of nested arrays!
Code Implementation Example
json
// JSON Patch (RFC 6902) explicit operation payload:
[
{ "op": "replace", "path": "/email", "value": "new@example.com" },
{ "op": "remove", "path": "/tags/0" },
{ "op": "test", "path": "/version", "value": 4 }
]💡RFC 6902 JSON Patch atomic operations array payload.
🎯 Interview Key Takeaway
Use JSON Merge Patch for simple object field updates; use JSON Patch (RFC 6902) for atomic, array-specific mutations.
#JSON Patch#RFC 6902#PATCH#Intermediate
Back to all REST APIs & Web Services Questions→