Idefixx Idefixx - 11 months ago 67
reST (reStructuredText) Question

Handling nulls in JSON Merge Patch

I am using

as my content type to edit a resource via HTTP PATCH method. I got my data stored in an RDBMS.

The merge patch spec clearly states that when a key is set to a
value, it should be deleted from the resource.

This is impossible for me to do however, as I cannot simply delete columns in my DB for certain rows - the values I 'delete' are simply set to
, which goes against the spec.

I thought of two options:

  1. Go against the spec and simply set the columns to
    , keeping them in the resource

  2. Use JSON patch instead, which is quite an overhead compared to merge patch

Is there some other way?

Answer Source

A DELETE on an API resource doesn't have to be actually deleting the resource in the DB - it could be a soft delete for that matter (which is what you're doing, in fact).

As long as it's properly represented as deleted by the API (e.g. you can omit displaying null values - I think JSON does that for you by default), it can be argued that you're respecting the spec.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download