Integration contracts
Decide what a field change means before constructing the PATCH request
Start with the intended action for each field: preserve its value, replace it, or remove it. Then map that action to the endpoint’s documented update format. A blank input, an absent property, an empty string and JSON null are not interchangeable instructions, and the HTTP method name alone does not choose their meaning.
JSON Merge Patch uses application/merge-patch+json. For object-member updates, omitted members remain unchanged and null removes an existing member. Non-object values replace their target rather than describing individual edits; this includes replacing an array as a whole. Those rules make explicit stored-null values a poor fit for some Merge Patch designs. (IETF / RFC Editor)
Keep business intent separate from form appearance
Imagine a fictional Swiss wholesaler updating a customer’s delivery preferences. Staff may leave a field alone, deliberately clear a delivery note or remove an obsolete alternate phone number. A blank text box can look the same in all three situations. No CRM, form or API was inspected or changed for this example.
The field owner should define the allowed actions, including any value that has a special business meaning. The integration owner should then find the endpoint’s media type, writable schema and provider-specific rules. Do not infer support for either standard merely because documentation lists PATCH, and do not use an existing UI’s blank display as the specification.
- Preserve: the person did not request a change to this field; retain that intent separately from any empty input control.
- Replace: the person supplied an allowed new value, which may itself be an empty string, empty collection or explicit null if the endpoint supports that meaning.
- Remove: the person deliberately asked to discard the member or value under the documented contract; make that action reviewable.
Apply one declared format at a time
Suppose the fictional wholesaler’s endpoint explicitly accepts Merge Patch and permits these optional fields. The business decision is to clear the note to an empty string, replace the complete tag list with an empty list and remove the alternatePhone member. The payload below is an invented illustration of those decisions, not a request sent to a service.
{
"deliveryNote": "",
"tags": [],
"alternatePhone": null
} (IETF / RFC Editor)Under that assumed contract, a separate field left out of the object is preserved. The phone member’s removal is different from storing null as its value. Replacing the tag array also means supplying the intended whole list; it is not an instruction to remove one matching tag from an existing list. (IETF / RFC Editor)
For the fictional team, review the three requested changes independently. Clearing the note should not silently clear a phone field that a hidden control failed to load. Removing one phone number should not remove the customer. An untouched field should survive a round trip. These are proposed business acceptance conditions, not behaviour observed in a particular CRM.
Use an explicit operation when that is the endpoint contract
JSON Patch instead uses application/json-patch+json and an ordered array of operations. It provides distinct remove and replace operations; both require an existing target. Its test operation checks a value using the specified JSON equality rules. Operations are evaluated in sequence and an unsuccessful operation means the patch is not considered successfully applied. (IETF / RFC Editor)
For contrast, assume another fictional endpoint declares JSON Patch, exposes an existing revision value and allows an existing deliveryNote to store explicit null. The following proposed sequence checks that illustrative revision before replacing the note with null. The revision field is part of this invented endpoint, not a universal feature of JSON Patch.
[
{ "op": "test", "path": "/revision", "value": 7 },
{ "op": "replace", "path": "/deliveryNote", "value": null }
] (IETF / RFC Editor)Here null is the replacement value of an explicit replace operation. A separate remove operation would ask to remove the member. The operation type, path and endpoint schema supply the meaning together; copying the first payload into the second media type would not preserve its contract. (IETF / RFC Editor)
The application must still decide whether the person is permitted to make that change and whether the record is still the one they reviewed. A field-level test can express a condition within an appropriate JSON Patch workflow, but it is not a substitute for the provider’s concurrency and authorisation design. Establish those requirements before choosing a payload.
Make the mapping reviewable before any write
For each important field, retain the business action, its source in the interface, the endpoint representation and the expected resource state afterwards. An integration review should be able to explain why a property was omitted or included, not merely display the final JSON. Hold an ambiguous action rather than automatically converting every blank into null.
- Begin with permitted synthetic records containing distinguishable values in changed and unchanged fields.
- Exercise preserve, replacement and removal as separate cases; include the empty values the schema actually permits.
- Check nested members and collection edits. Establish whether the intended action affects one item or replaces a whole value.
- Include a missing target, a failed condition and an uncertain response. Define the next decision before allowing a retry.
- Compare the resulting resource with the intended field actions and retain any provider normalisation, defaults or omitted response fields as part of the observed contract.
No cases were run for this guide. A later readback also needs interpretation: a blank screen or a response that normalises missing members to null may not reveal the distinction the integration is trying to establish. Use the provider’s documented representation and the evidence available for the chosen field. Do not announce a verified removal from a generic success message alone.
Keep a failed attempt distinct from an unknown outcome
If the service rejects the request, keep the rejected action and its reason. If the connection ends without a clear result, establish the current resource state before sending the mutation again. A repeat may no longer have the same preconditions or target. The recovery decision should identify which field intent remains outstanding, rather than blindly replaying the entire form.
The RFCs describe interoperable formats; they do not establish which operations a particular commercial service supports, what an account may change or what it costs. Their published document and code-component rights remain separate from the chosen implementation, API plan and customer-data permissions. Budget mapping, exception handling and acceptance work without claiming a measured saving.
Start with one field where losing the current value would matter. Have its business and integration owners agree the preserve, replace and remove outcomes, then select the supported representation. A small explicit mapping is a stronger handover than a large payload whose empty values nobody can explain.
Sources
- RFC 7396 — JSON Merge Patch — IETF / RFC Editor
- RFC 6902 — JavaScript Object Notation JSON Patch — IETF / RFC Editor