Skip to content
Astera Technology

Separate omitted fields from null in an API patch

Check patch semantics before allowing a blank form field to erase existing data.

Use the documented patch format

In JSON Merge Patch, an absent member leaves it unchanged and null removes it. Other PATCH formats can mean something else. The sample applies merge-patch semantics to a synthetic profile object; it is not a rule for every JSON request.

Worked merge-patch field example
BeforePatchAfter
phone="1234", note="call"{"note":"email"}phone retained; note="email"
phone="1234"{"phone":null}phone member removed
phone="1234"{"phone":""}phone becomes empty string if accepted
Download editable CSV ↓

Map user edits to an intentional patch

Track unchanged, changed and explicitly cleared fields separately. Decide whether the domain permits an empty string or removal and validate that decision. For fields where actual null must be stored, merge patch may not express the required distinction; use the target’s supported alternative.

A user opens a profile and leaves phone untouched. Should the adapter emit phone:null?

Show the worked answer

Not under merge-patch semantics. Omit unchanged phone; emit removal only for an explicit authorised clear action.

Related resources