1

What is the standard outcome of the following 'remove' JSON Patch with an empty "" path?

[{ "op": "remove", "path": ""}]

Should it clear the whole object, equal to assigning {}? In http://jsonpatch.com/ it says: To point to the root of the document use an empty string for the pointer. So I guess a 'remove' on the root removes the whole object, right?

I tried it with two different JSON Patch libraries with two different results:

What is the officially accepted, standard outcome of this? I checked in the RFC for the JSON Patch (https://www.rfc-editor.org/rfc/rfc6902) but couldn't find anything.

Community
  • 1
  • 1
Kris
  • 4,595
  • 7
  • 32
  • 50

1 Answers1

1

RFC 6902 references this for further error handling: https://www.rfc-editor.org/rfc/rfc5789#section-2.2

And to me, this part seems to fit the bill:

Resource not found:  Can be specified with a 404 (Not Found) status
  code when the client attempted to apply a patch document to a non-
  existent resource, but the patch document chosen cannot be applied
  to a non-existent resource.

Since you basically did not define any resource - not even / which would more clearly refer to the root / the entire object.

I guess the difference in the two libraries comes from that these two are usually considered identical:
/my/resource
/my/resource/

But usually the non-/ path would be automatically 301 Redirected to the path that does have /. So I would personally go with the 404 response for "path": ""

Community
  • 1
  • 1
Juha Untinen
  • 1,806
  • 1
  • 24
  • 40
  • Thanks for pointing to the RFC5789. I haven't looked in there yet. Although it's seems like RFC5789 is especially for when JSON Patch is used with the HTTP PATCH method. – Kris Sep 24 '17 at 22:34
  • Please refer to [RFC 6901](https://tools.ietf.org/html/rfc6901) to understand path property in question. Empty path define resource: the entire object, also "/" path is not equivalent of root. `{"": "me defined by '/' path!"}` Removing root is not defined by RFC, but to make 'replace' operation functional 'remove' must remove whole object and return success. – crimaniak May 19 '18 at 21:24