Skip to content
Wade Womersley

wade.one

wade womersley – york based software engineer

  • Home
  • 2026
  • November
  • 16
  • Missing and Null Need Different Rules in a PATCH API

Missing and Null Need Different Rules in a PATCH API

Posted on November 16, 2026November 12, 2026 By
Programming

If I leave a field out of a partial update, I usually mean “leave it alone”. If I deliberately clear it, I expect the API to have a way to express that. Collapsing both requests into the same value is a small implementation shortcut that can make an edit form surprisingly destructive.

Consider a profile with an optional nickname. These payloads need a documented meaning:

{}
{"nickname": null}

For an endpoint using JSON Merge Patch, the first leaves the nickname unchanged and the second removes that member from the target JSON document. That format uses application/merge-patch+json. Its rules do not automatically apply to every endpoint called PATCH; choose and document the request format rather than expecting the HTTP method to explain the body.

There is a useful limitation here too. Merge Patch gives null a removal meaning, so it is awkward when storing an explicit JSON null is itself a meaningful operation. Arrays are replaced as a whole rather than edited item by item. If those rules do not fit the resource, choose a format that does. Calling an endpoint a partial update does not settle those decisions.

The implementation needs to preserve field presence from parsing through to persistence. A request mapper that fills every omitted property with null has already lost the information. So has validation that supplies a default before the update code can tell whether the client sent the field. Defaults that make sense when creating a record can be wrong when editing one.

I would make the contract explicit for the fields the endpoint allows people to change. Omitted means unchanged; a supplied value is validated and applied; an explicit clear is either supported or rejected with a useful explanation. An empty string should follow the field’s own rules too. It might be valid text, an invalid value or a documented way to clear something, but it should not acquire a meaning by accident.

This is worth a small test through the real request handling: change one field and check that an omitted neighbouring field survives, then explicitly clear the optional field and check the intended result. A unit test of the final update function can miss the mapper that erased the distinction several steps earlier.

Share:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit

Related

Comments

comments

Tags: api json-merge-patch validation

Post navigation

❮ Previous Post: Every Game Inventory Becomes a Museum of Things I Might Need Later

You may also like

Programming
Cloudant (IBM) Query – Indexing arrays directly using Erlang
July 6, 2015
Programming
What I Check Before I Trust a Mobile Release
April 13, 2026
Programming
Offline Support Sounds Smaller Than It Is
April 9, 2026
Programming
TypeScript 7.0 Looks Like the Bigger Story
March 25, 2026
  • AI
  • artificial intelligence
  • Ego-centric
  • Events
  • Films
  • Food
  • Gaming
  • Gym
  • Hardware
  • Holidays
  • News
  • PHP
  • Programming
  • Random Stuff
  • Reviews
  • Science
  • SEO
  • Software
  • Software Engineer
  • Support
  • Uncategorized
  • Work

Copyright © 2026 wade.one.

Theme: Oceanly News Dark by ScriptsTown